On Aug 27, 2007, at 11:13 AM, Paul Cochrane (via RT) wrote:
# New Ticket Created by Paul Cochrane
# Please include the string: [perl #44995]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=44995 >
Hi everyone,
Another issue raised by Coverity Prevent[1] is that of a NULL pointer
being dereferenced. This occurs as a result of the following code
(from src/dynoplibs/myops.ops:54):
int *a, i;
a = NULL;
i = *a;
Note that i is assigned to *a which is set to NULL. Coverity picks
this up as being a bad thing. Should this be
a = NULL;
i = NULL;
??
The reason I send this question to the list rather than just "fixing"
the issue is because whenever pointers are involved I get nervous and
like to seek the help of higher intelligences than myself.
- is the original code ok? If not, how should it be changed to be
safe?
- is Coverity just throwing up a false positive?
- what is the meaning of assigning NULL to a variable (which is
declared as a pointer) and then using that to initialise another
variable which *isn't* a pointer. This is a fine point, and is
therefore where I'm lacking knowledge as to what exactly the code
means.
Many thanks to anyone who helps me out on this!
Paul
[1] For those with Coverity Prevent accounts, see CIDs 80, 81, 82
I recall this problem. If you look at the documentation above the
code, it says "Halt and Catch Fire. Tries to crash parrot." Instead of
a simple dereferencing null, some compilers optimize away unused code
so it was rewritten to guarantee it would dereference a null pointer.
Oh, and it's not suppose to be safe. Coverity's right.