Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| sei_cert_c_coding_standard [2019/08/06 21:04] – [2.2 PRE31-C. Avoid side effects in arguments to unsafe macros] rpjday | sei_cert_c_coding_standard [2019/08/06 21:17] (current) – [3.5 DCL38-C. Use the correct syntax when declaring a flexible array member] rpjday | ||
|---|---|---|---|
| Line 23: | Line 23: | ||
| </ | </ | ||
| ==== 2.3 PRE32-C. Do not use preprocessor directives in invocations of function-like macros ==== | ==== 2.3 PRE32-C. Do not use preprocessor directives in invocations of function-like macros ==== | ||
| + | |||
| + | 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, | ||
| + | #ifdef PLATFORM1 | ||
| + | 12 | ||
| + | #else | ||
| + | 24 | ||
| + | #endif | ||
| + | ); | ||
| + | /* ... */ | ||
| + | } | ||
| + | </ | ||
| ===== 3 Declarations and Initialization (DCL) ===== | ===== 3 Declarations and Initialization (DCL) ===== | ||
| Line 36: | Line 54: | ||
| ==== 3.5 DCL38-C. Use the correct syntax when declaring a flexible array member ==== | ==== 3.5 DCL38-C. Use the correct syntax when declaring a flexible array member ==== | ||
| + | * 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[]; | ||
| + | }; | ||
| + | </ | ||
| ==== 3.6 DCL39-C. Avoid information leakage when passing a structure across a trust boundary ==== | ==== 3.6 DCL39-C. Avoid information leakage when passing a structure across a trust boundary ==== | ||