I'm not sure this particular case worth to be included into the cppcheck, but still reporting it. Here is the simplified peace of code:
int *ptr;
int main(void)
{
if (ptr != NULL) {
while (1);
}
printf("%d", *ptr);
}
For this case, cppcheck reports the nullPointerRedundantCheck id, considering, as far as I understand, that there is a chance to dereference the null pointer. Though it is impossible, as the program gets stuck in the eternal while loop.
This is not a typical scenario for the PC programs, but quite ubiquitous in the embedded world, where the piece of code above eventually triggers the watchdog or some other protecting feature, causing a program to restore its behavior.
Hello to community!
I'm not sure this particular case worth to be included into the
cppcheck, but still reporting it. Here is the simplified peace of code:For this case, cppcheck reports the nullPointerRedundantCheck id, considering, as far as I understand, that there is a chance to dereference the null pointer. Though it is impossible, as the program gets stuck in the eternal
whileloop.This is not a typical scenario for the PC programs, but quite ubiquitous in the embedded world, where the piece of code above eventually triggers the watchdog or some other protecting feature, causing a program to restore its behavior.
Thanks for your attention.
If
ptrisNULLinmain(), thewhileloop is not entered, and the pointer will be dereferenced. So the warning seems correct to me.