OSDN Git Service

Work around coverity being stupid (CID 182336/REVERSE_INULL)
authorPeter Jones <pjones@redhat.com>
Tue, 26 Sep 2017 17:42:16 +0000 (13:42 -0400)
committerPeter Jones <pjones@redhat.com>
Tue, 26 Sep 2017 17:47:59 +0000 (13:47 -0400)
commit1f18f4708682c253cf2c20b12927957b683fb77d
tree8dcb4d1a151f944ee1beda5b7065255bc90466a8
parentc8c7df104cc6e2410a0bd5ba92a124bf1240c687
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>
src/efivarfs.c
src/vars.c