Are there any tools (preferably on linux) that can warn when an argument is defined as a smaller array then the prototype specifies?
eg:
void somefunc(float arg[10]); /* normally this would be defined in a header */
void my_func(void)
{
float arg[2];
somefunc(arg); /* <-- this could be a warning */
}
I realize this isn’t invalid code but it could resolve some common mistakes if it were possible to warn of it (ran into one of these bugs recently).
Some tools (clang static checker for eg), will warn if the function is in the same file and sets a value outside the array bounds, but I was wondering if anything will warn if the arg is smaller then the prototype alone.
I’ve used cppcheck, clang, smatch, splint, gcc’s -Wextra… but none complain of this.
Since asking this question, cppcheck has added this feature in response to my suggestion (thanks guys!),
Commit:
https://github.com/danmar/cppcheck/commit/7f6a10599bee61de0c7ee90054808de00b3ae92d
Issue:
http://sourceforge.net/apps/trac/cppcheck/ticket/4262
At the time of writing this isn’t yet in a release, but I assume it will be in the next release.