...
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 /* ... */ ); |
Compliant Code Example
In this compliant solution [GCC Bugs], the appropriate call to memcpy()
is determined outside the function call:
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string.h> void func(const char *src) { /* validate the source string, calculate size */ char *dest; /* malloc destination string */ #ifdef PLATFORM1 memcpy(dest, src, 12); #else memcpy(dest, src, 24); #endif } |
Risk Assessment
Improper use of macros may result in undefined behavior.
...