Is it possible to handle a custom assert-style macro?
In our code these asserts cause a system reboot when an invalid state is detected, and hence execution never proceeds past the macro if the expression evaluates to false.
For that reason cppcheck will often warn about accesses out of bounds, eg:
Aha - got it. Thanks for the pointer. Yes, there's a function call that reboots the system and it has a noreturn attribute.
We were checking the condition using the ?: ternary operator, which seems to have misled cppcheck. Replacing this with an if statement resolves the issue.
Many thanks!
Jon
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Is it possible to handle a custom assert-style macro?
In our code these asserts cause a system reboot when an invalid state is detected, and hence execution never proceeds past the macro if the expression evaluates to false.
For that reason cppcheck will often warn about accesses out of bounds, eg:
The second ASSERT macro here gives a warning, even though execution will have stopped at the line before if resource_num is out of range.
Thanks!
Jon
How is your ASSERT macro defined? If the condition is false it must do something that cause system reboot. Is it a function call?
Spontaneously I think there are two options here. Either hide the macros for Cppcheck:
Or show Cppcheck that the macros terminate if the condition is false. Like:
For information... I get no warning with this code:
Aha - got it. Thanks for the pointer. Yes, there's a function call that reboots the system and it has a noreturn attribute.
We were checking the condition using the ?: ternary operator, which seems to have misled cppcheck. Replacing this with an if statement resolves the issue.
Many thanks!
Jon
ok then it is a bug in Cppcheck. do you think you could tweak my example code so it looks more like your code and then gives a FP?