Hello, is there a way to check follow
void test() { .... if (c) return; // ok: no os_leave needed, because there is no os_enter before
if (d) { os_leave(); // ERROR os_leave without a os_enter() return; }
os_enter(); if (a) { os_leave(); return; // OK , } if (b) { return; // BUG os_leave missing } os_leave(); }
os_enter / os_leave has a internal reference counter os_enter=++ and os_leave=-- Thanks
I don't really remember. I have the feeling we discussed this some 10-15 years ago I don't remember if we did anything.
wild idea you could define preprocessor macros..
#ifdef __cppcheck__ // macros for cppcheck analysis #define check_os_enter_leave() void* __checkPtr #define os_enter() __checkPtr = malloc(100); #define os_leave() free(__checkPtr); #else // macros used in compilation #define check_os_enter_leave() #endif void test() { check_os_enter_leave(); if (c) return; // ok if (d) { os_leave(); // ERROR os_leave without a os_enter() return; } os_enter(); if (a) { os_leave(); return; // OK , } if (b) { return; // BUG os_leave missing } os_leave(); }
You will get a bit strange errors about uninitialized variable usage / memory leak.. but you will see errors.
note that the drawback is that you must call check_os_enter_leave(); at the start of the function otherwise this hack does not work.
check_os_enter_leave();
As I said I don't remember exactly what builtin checking we have for this. possibly there is something better..
thanks, i will test your solution.
Log in to post a comment.
Hello,
is there a way to check follow
void test()
{
....
if (c)
return; // ok: no os_leave needed, because there is no os_enter before
if (d) {
os_leave(); // ERROR os_leave without a os_enter()
return;
}
os_enter();
if (a) {
os_leave();
return; // OK ,
}
if (b) {
return; // BUG os_leave missing
}
os_leave();
}
os_enter / os_leave has a internal reference counter os_enter=++ and os_leave=--
Thanks
I don't really remember. I have the feeling we discussed this some 10-15 years ago I don't remember if we did anything.
wild idea you could define preprocessor macros..
You will get a bit strange errors about uninitialized variable usage / memory leak.. but you will see errors.
Last edit: Daniel Marjamäki 2022-02-12
note that the drawback is that you must call
check_os_enter_leave();
at the start of the function otherwise this hack does not work.As I said I don't remember exactly what builtin checking we have for this. possibly there is something better..
thanks, i will test your solution.