we have some functionality for such fully automatic multi-file checking. but it's not used much. the unused functions uses it. And the CheckBufferOverrun uses it to check external buffers.
If you want to detect that memory leak now you should use a cfg file. If you provide some configuration Cppcheck will detect the leak in your code.
Start by using the --check-library flag:
$ cppcheck a.c b.c --check-library --enable=information
[a.c:3]: (information) --check-library: There is no matching configuration forfunctionif()[a.c:4]: (information) --check-library: There is no matching configuration forfunction func2()[a.c:4]: (information) --check-library: Function func2() should have <noreturn> configuration
[a.c:5]: (information) --check-library: Function func2() should have <use>/<ignore> configuration
I recommend that you fix all messages about <noreturn>, that will help lots of checkers. You could find many additional types of bugs if you configure this properly.
Fixing the <use> / <ignore> message will help Cppcheck detect leaks.
hi,
does cppcheck support finding bugs between c files functions?
for example:
a.c:
void func1(void) {
void * p = malloc(1024);
if(p)
func2(p);
}
b.c:
void func2(void *p) {
printf("%p\n",p);
}
in this example we have a memleak of p.
running cppcheck on this files doesnt report anything.
is there a way to find this kind of bugs?
thanks,
tal
we have some functionality for such fully automatic multi-file checking. but it's not used much. the unused functions uses it. And the CheckBufferOverrun uses it to check external buffers.
If you want to detect that memory leak now you should use a cfg file. If you provide some configuration Cppcheck will detect the leak in your code.
Start by using the --check-library flag:
I recommend that you fix all messages about <noreturn>, that will help lots of checkers. You could find many additional types of bugs if you configure this properly.
Fixing the <use> / <ignore> message will help Cppcheck detect leaks.
For some information about how cfg files are written see chapter 7 in the manual http://cppcheck.sourceforge.net/manual.html. I am afraid the manual is not very good.
Here is an example configuration:
Put that configuration in the file ab.cfg. Then when you use that the result is:
I even expected that it would also write this:
However the condition on line 3 in a.c somehow prevents that... I'll investigate if that can be fixed.
Last edit: Daniel Marjamäki 2015-02-02