...
In this noncompliant code example [GCC Bugs], the programmer uses preprocessor directives to specify platform-specific arguments to memcpy(). However, if memcpy() is implemented using a macro, the code results in in undefined behavior 92.
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <string.h>
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
);
/* ... */
}
|
...
Including preprocessor directives in macro arguments is is undefined behavior 92.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
PRE32-C | Low | Unlikely | Medium | P2 | L3 |
...