sei_cert_c_coding_standard

An unsafe function-like macro is one whose expansion results in evaluating one of its parameters more than once or not at all.

#define ABS(x) (((x) < 0) ? -(x) : (x)) /* UNSAFE */
  
void func(int n) {
  /* Validate that n is within the desired range */
  ++n;
  int m = ABS(n);
 
  /* ... */
}

The arguments to a macro must not include preprocessor directives, such as #define, #ifdef, and #include.

void func(const char *src) {
  /* Validate the source string; calculate size */
  char *dest;
  /* malloc() destination string */
  memcpy(dest, src,
    #ifdef PLATFORM1
      12
    #else
      24
    #endif
  );
  /* ... */
}
  • The incomplete array type must be the last element within the structure.
  • There cannot be an array of structures that contain a flexible array member.
  • Structures that contain a flexible array member cannot be used as a member of another structure.
  • The structure must contain at least one named member in addition to the flexible array member.
struct flexArrayStruct{
  int num;
  int data[];
};
  • sei_cert_c_coding_standard.txt
  • Last modified: 2019/08/06 21:17
  • by rpjday