Warn about initialization of a char array with a too long constant C string.
commitc3430e57bc57ff40d5ce95ef2d26b8d70346f58f
authorMasatake YAMATO <yamato@redhat.com>
Sat, 6 Apr 2013 16:58:55 +0000 (7 01:58 +0900)
committerChristopher Li <sparse@chrisli.org>
Sat, 20 Apr 2013 03:53:56 +0000 (19 20:53 -0700)
treeedb275321fa638e2abbb2809940c2745b583c19c
parentc560e34449fa9e804a01204ca50bb9ed2a190935
Warn about initialization of a char array with a too long constant C string.

This patch adds new option -Winit-cstring to sparse.

With the option sparse can Warn about initialization of a char array
with a too long constant C string.  If the size of the char array and
the length of the string is the same, there is no space for the last
nul char of the string in the array.

              char s[3] = "abc";

If the array is used as just a byte array, not as C string, this
warning is just noise. However, if the array is passed to functions
dealing with C string like printf(%s) and strcmp, it may cause a
trouble.

Here is a example of such trouble:
     http://www.spinics.net/lists/netdev/msg229765.html
     http://www.spinics.net/lists/netdev/msg229870.html

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
evaluate.c
lib.c
lib.h