Synopsis
use C::Check 'check_functions';
# File::Slurper etc.
my $c = read_text ('file.c');
check_functions ($c);
e.g. calloc arguments in wrong order, uses gets, insists on comments at switch fallthroughs, optionally complains about using assert, etc.
Description
C compilers typically don't warn about daft mistakes like putting function arguments in the wrong order, or using the wrong size of a variable, or things like not checking the return value of malloc, etc. This module would check for typical errors in C programs like switch fallthroughs, use of equals instead of == in an if statement, insist on using braces with if statements, bad if statement indentation, like
if (x)
printf ("reached");
printf ("reached even if x is not true, despite this indentation");
etc.
At the moment I have a script which does something like the above, wondering whether it would be worth working up into a module.
Comments
bla.c: In function ‘main’:
bla.c:14:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
if (0)
^~
bla.c:16:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
printf("2\n");
^~~~~~
These are the kinds of jobs I'm already doing with my hacky script. I wonder if it is worth converting the hacky script into a proper module and releasing it.
Please sign up to post a review.