int Test6() {
  int sum = 0;

  struct S A = AsStruct(), B = AsStruct();
  struct S *P = &A, *Q = &B;
  sum += sizeof(struct S) == P - Q;
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += 5 * sizeof(S) != P - Q;
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += sizeof(S) < P - Q;
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += 5 * sizeof(S) <= P - Q;
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += 5 * sizeof(*P) >= P - Q;
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += Q - P > 3 * sizeof(*P);
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += sizeof(S) + (P - Q);
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += 5 * sizeof(S) - (P - Q);
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += (P - Q) / sizeof(S);
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
  sum += (P - Q) / sizeof(*Q);
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic

  return sum;
}
Exemplo n.º 2
0
const char * GFFField::tostring(char * buffer, int nMax, int nIndex){

	switch (this->Type){

		case 0:sprintf(buffer, "%u", AsByte()); break;
		case 1:sprintf(buffer, "%d", AsChar()); break;
		case 2:sprintf(buffer, "%u", AsWord()); break;
		case 3:sprintf(buffer, "%d", AsShort()); break;
		case 4:sprintf(buffer, "%u", AsDword()); break;
		case 5:sprintf(buffer, "%d", AsInt()); break;
		case 6:sprintf(buffer, "%llu", AsDword64()); break;
		case 7:sprintf(buffer, "%lld", AsInt64()); break;
		case 8:sprintf(buffer, "%f", AsFloat()); break;
		case 9:sprintf(buffer, "%Lf", AsDouble()); break;
		case 10:strncpy(buffer, AsExoString()->str, nMax); break;
		case 11:strncpy(buffer, AsResRef()->str, nMax); break;
		case 12:
			
			if (nIndex >= (int)AsExoLocString()->StringCount)
				buffer[0] = '\0';
			else				
				strncpy(buffer, AsExoLocString()->SubString[nIndex].str, nMax); 
			break;
		case 13:sprintf(buffer, "<binary %u bytes>", AsVoid()->Size); break;
		case 14:sprintf(buffer, "struct ID: %d", AsStruct()->Type ); break;
		case 15:sprintf(buffer, "list %i entries", AsList()->Size); break;
		default:buffer[0] = '\0'; break;
	}

	return buffer;
}
int ValidExpressions() {
  int A[] = {1, 2, 3, 4};
  static const char str[] = "hello";
  static const char* ptr[] { "aaa", "bbb", "ccc" };
  int sum = 0;
  if (sizeof(A) < 10)
    sum += sizeof(A);
  sum += sizeof(int);
  sum += sizeof(AsStruct());
  sum += sizeof(M{}.AsStruct());
  sum += sizeof(A[sizeof(A) / sizeof(int)]);
  sum += sizeof(&A[sizeof(A) / sizeof(int)]);
  sum += sizeof(sizeof(0));  // Special case: sizeof size_t.
  sum += sizeof(void*);
  sum += sizeof(void const *);
  sum += sizeof(void const *) / 4;
  sum += sizeof(str);
  sum += sizeof(str) / sizeof(char);
  sum += sizeof(str) / sizeof(str[0]);
  sum += sizeof(ptr) / sizeof(ptr[0]);
  sum += sizeof(ptr) / sizeof(*(ptr));
  return sum;
}