]> git.ipfire.org Git - thirdparty/libvirt.git/commit
virpci: Resolve coverity issues
authorJohn Ferlan <jferlan@redhat.com>
Thu, 6 Feb 2014 17:30:57 +0000 (12:30 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 7 Feb 2014 15:58:24 +0000 (10:58 -0500)
commitb60644f38fe4d754c0f738f42bf9dbec294e8235
tree2478bde76a1e17b9527b3c78896418fdcd789b97
parentf336b1cccb2bd92ae038b48da5fc735ec0a68f40
virpci: Resolve coverity issues

Coverity complains about "USE_AFTER_FREE" due to how virPCIDeviceSetStubDriver
"could" return either -1, 0, or 1 from the VIR_STRDUP() and then possibly makes
a call to virPCIDeviceDetach().

The only way this could happen is if NULL were passed as the "driver" name
and virStrdup() returned 0.  Since the calling functions check < 0 on the
initial function call, the 0 possibility causes Coverity to complain.

To fix this - enforce that the second parameter is not NULL using
ATTRIBUTE_NONNULL(2) for the function prototype, then in virPCIDeviceDetach
add an sa_assert(dev->stubDriver). This will result in Coverity not complaining
any more.
src/util/virpci.c
src/util/virpci.h