Hi guys,
I discovered a false positive with some (ancient) use of an initialiser to initialise a character array on the stack to an empty string.
I tried to create a Trac account to create a ticket but somehow didn't receive the email.
Here's a demo program to show the warning:
#include <stdio.h> int main (int argc, char **argv) { char str[6] = "\0"; unsigned short port = 65535; snprintf (str, sizeof (str), "%hu", port); }
The warning is:
[test.c:8]: (error) Buffer is accessed out of bounds.
The only way to removing the warning is to get rid of the "\0".
The false positive should still be fixed, but why not just do
char str[6] = {};
Fixed by: https://github.com/danmar/cppcheck/commit/644a2163945340d2df6f4390781730bb74238567
Log in to post a comment.
Hi guys,
I discovered a false positive with some (ancient) use of an initialiser to initialise a character array on the stack to an empty string.
I tried to create a Trac account to create a ticket but somehow didn't receive the email.
Here's a demo program to show the warning:
The warning is:
[test.c:8]: (error) Buffer is accessed out of bounds.
The only way to removing the warning is to get rid of the "\0".
The false positive should still be fixed, but why not just do
Fixed by:
https://github.com/danmar/cppcheck/commit/644a2163945340d2df6f4390781730bb74238567