Suppose you have a code like this:
int* a = (int*) malloc(20);
a[3]=2;
pid_t q = fork();
if(!q) {
char *a[5];
for (q=4; ;--q) {
if(q<0) break;
a[q]="q";
}
execve("q", a, NULL);
}
if(q) kill(q, 9);
free(a);
It builds without any warning with gcc -Wall
, clang -Wall
, emits no warnings with cppcheck --enable=all
.
Hovewer ommitted checking of malloc
, fork
and execve
's return values for errors clearly leads to problems. How do I statically check the C source code for such mistakes?