01.07.2016 Views

SEI CERT C Coding Standard

tqcylJ

tqcylJ

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Preprocessor (PRE) - PRE32-C. Do not use preprocessor directives in invocations of function-like macros<br />

2.3.2 Compliant Solution<br />

In this compliant solution [GCC Bugs], the appropriate call to memcpy() is determined outside<br />

the function call:<br />

#include <br />

void func(const char *src) {<br />

/* Validate the source string; calculate size */<br />

char *dest;<br />

/* malloc() destination string */<br />

#ifdef PLATFORM1<br />

memcpy(dest, src, 12);<br />

#else<br />

memcpy(dest, src, 24);<br />

#endif<br />

/* ... */<br />

}<br />

2.3.3 Risk Assessment<br />

Including preprocessor directives in macro arguments is undefined behavior.<br />

Rule Severity Likelihood Remediation Cost Priority Level<br />

PRE32-C Low Unlikely Medium P2 L3<br />

2.3.4 Bibliography<br />

[GCC Bugs]<br />

[ISO/IEC 9899:2011]<br />

“Non-bugs”<br />

6.10.3, “Macro Replacement”<br />

<strong>SEI</strong> <strong>CERT</strong> C <strong>Coding</strong> <strong>Standard</strong>: Rules for Developing Safe, Reliable, and Secure Systems 31<br />

Software Engineering Institute | Carnegie Mellon University<br />

[DISTRIBUTION STATEMENT A] Approved for public release and unlimited distribution.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!