As part of my program, I used following code:
///////////////
98:::printf("%d",abc->stv)
//////////////
100::if(abc)
//////////////
(the following error was produced)
Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 100
if (abc)
tests whether abc
is a null pointer or not.
The compiler is warning you that you've already assumed that abc
is not a null pointer (by dereferencing it on line 98), which means either
if (abc)
test is redundant (because it will never be true) or abc
on line 98 is potentially incorrect because abc
might in fact be null. If you test for abc
it means to the compiler it might be null. Therefore dereferencing the pointer like in abc->stv
is a possible error. A solution is to enclose the printf
code inside the if
block:
if(abc)
{
printf("%d",abc->stv)
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.