If the checker is silent whenever there is a function call, the checker will not be very effective. If function calls are ignored it will produce false positives.
It could use whole-program-analysis to make it a bit more effective but that does not help if libs/etc are called.
Last edit: Daniel Marjamäki 2018-08-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This would just be a matter of adding the functions to the library config files, right?
It would be possible to check lock/unlock with cppcheck with some tweaks.
I don't know if you like it .. but you can for instance try this:
Create two new functions for locking/unlocking:
// The functions below are needed by the compiler, but must be hidden in cppcheck analysis. You can use -DCPPCHECK to hide them.#ifndef CPPCHECKintsafe_mutex_lock(){mutex_lock();return0;}voidsafe_mutex_unlock(int){mutex_unlock();}#endif
Then use the "safe" lock/unlock functions in the code:
void foo() {
int safe_lock = safe_mutex_lock();
if (condition) { // condition is true
return;
}
safe_mutex_unlock(safe_lock);
}
Hi folks,
is there a way that Cppcheck checks the mutex locking / unlocking functionalitites?
An example (with an error):
Is there a way Cppcheck can detect such a problem (the mutex stays locked)?
Cheers
This is not yet possible but there is already at least one ticket suggestion such functionality:
https://trac.cppcheck.net/ticket/7315
I am skeptic that we can write an effective checker for this.. What if there is a function call..
If the checker is silent whenever there is a function call, the checker will not be very effective. If function calls are ignored it will produce false positives.
It could use whole-program-analysis to make it a bit more effective but that does not help if libs/etc are called.
Last edit: Daniel Marjamäki 2018-08-11
Dont we do similiar analysis already for resource leaks? This would just be a matter of adding the functions to the library config files, right?
The checker only checks local pointer variables. So we don't have so much problem with function calls.
If the pointer is made global then the checker will not warn.
It would be possible to check lock/unlock with cppcheck with some tweaks.
I don't know if you like it .. but you can for instance try this: