...
| Code Block | ||
|---|---|---|
| ||
long long a = 1; char msg[128] = "Default message"; /* ... */ printf("%d %s", a, msg); |
Because a long long was not interpreted, if the architecture is set up in a way that long long uses more bits for storage, the subsequent format specifier %s will be unexpectedly offset, causing unknown data to be used instead of the pointer to the message.
Compliant Solution 2
This compliant solution adds in the length modifier ll to the %d format specifier so that the variadic function parser for printf() pulls the right amount of space off of the variable argument list for the long long argument.
| Code Block | ||
|---|---|---|
| ||
long long a = 1; char msg[128] = "Default message"; /* ... */ printf("%lld %s", a, msg); |
...