...
This example is still problematic because a buffer overflow will occur if the null-terminated byte string referenced by msg
is greater than 17 characters, including the null terminator. For more information, see STR31-C. Guarantee that storage for strings has sufficient space for character data and the null terminator.
Compliant Solution
In this compliant solution, the buffer overflow is eliminated by using the snprintf()
function:
...