OSDN Git Service
Work around coverity being stupid (CID 182336/REVERSE_INULL)
Coverity *really* doesn't like testing a string that's been previously
dereferenced, because they believe programs are written once and nothing
ever changes, and they don't believe common error paths should plan for
that to happen.
Thus, if you do:
int
foo(void)
{
int ret = -1, rc;
char *path = NULL;
rc = asprintf(&path, "foo");
if (rc < 0)
return -1; // because this is return, not goto err ...
// lots of stuff ...
if (rc < 0)
goto err; // ... and this is goto err ...
// stuff ...
ret = 0;
err:
if (path) // ... CID 182336 (REVERSE_INULL) triggers here
free(path);
return ret;
}
Even though this is perfectly reasonable code that does not contain any
actual bugs, coverity's REVERSE_INULL check complains about the test on
path. This isn't a complaint about the code - it's an error message
about coverity's inability to infer why you've done it. And why you've
done it is so that if the code above changes, the error path doesn't
suddenly become unsafe.
So change the error path usage so that it will also jump to the common
error path, which is completely unnecessary, when path could be NULL.
Yes, this is stupid.
Signed-off-by: Peter Jones <pjones@redhat.com>