[libvirt] [PATCH 0/4] Resolve some UNUSED_VALUE errors found by Coverity

This patch resolves "UNUSED_VALUE (CWE-563)" errors found by Coverity. John Ferlan (4): locking: Remove unnecessary setting of lockspace util: Remove the unused setting of 'res' for virHashLookup return virsh: Remove unused setting of 'br_node' and 'if_node' parallels: Remove unused JSON fetch of "OS" src/locking/lock_daemon_dispatch.c | 4 ++-- src/parallels/parallels_driver.c | 3 --- src/util/virlockspace.c | 6 ++---- tools/virsh-interface.c | 6 +++--- 4 files changed, 7 insertions(+), 12 deletions(-) -- 1.7.11.7

In virLockSpaceProtocolDispatchNew() the returned value of lockspace from virLockDaemonFindLockSpace() is overwritten by the virLockSpaceNew() return. Coverity complains that it's unused. In virLockSpaceProtocolDispatchCreateLockSpace() lockspace is also overwritten in a similar manner resulting in the same Coverity message. --- src/locking/lock_daemon_dispatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index 45d2cae..4c99088 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -227,7 +227,7 @@ virLockSpaceProtocolDispatchNew(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } - if ((lockspace = virLockDaemonFindLockSpace(lockDaemon, args->path))) { + if (virLockDaemonFindLockSpace(lockDaemon, args->path) != NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Lockspace for path %s already exists"), args->path); @@ -406,7 +406,7 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server ATTRIBUTE_UNU goto cleanup; } - if ((lockspace = virLockDaemonFindLockSpace(lockDaemon, args->path))) { + if (virLockDaemonFindLockSpace(lockDaemon, args->path) != NULL) { virReportError(VIR_ERR_OPERATION_INVALID, _("Lockspace for path %s already exists"), args->path); -- 1.7.11.7

--- src/util/virlockspace.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 04aeebe..163404f 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -558,13 +558,12 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace, { int ret = -1; char *respath = NULL; - virLockSpaceResourcePtr res; VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname); virMutexLock(&lockspace->lock); - if ((res = virHashLookup(lockspace->resources, resname))) { + if (virHashLookup(lockspace->resources, resname) != NULL) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), resname); @@ -591,13 +590,12 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace, { int ret = -1; char *respath = NULL; - virLockSpaceResourcePtr res; VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname); virMutexLock(&lockspace->lock); - if ((res = virHashLookup(lockspace->resources, resname))) { + if (virHashLookup(lockspace->resources, resname) != NULL) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), resname); -- 1.7.11.7

--- tools/virsh-interface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index cd14e89..1e047b2 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -920,7 +920,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) int if_xml_size; xmlDocPtr xml_doc = NULL; xmlXPathContextPtr ctxt = NULL; - xmlNodePtr top_node, br_node, if_node, cur; + xmlNodePtr top_node, if_node, cur; /* Get a handle to the original device */ if (!(br_handle = vshCommandOptInterfaceBy(ctl, cmd, "bridge", @@ -963,12 +963,12 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) VIR_FREE(if_name); /* Find the <bridge> node under <interface>. */ - if (!(br_node = virXPathNode("./bridge", ctxt))) { + if (virXPathNode("./bridge", ctxt) == NULL) { vshError(ctl, "%s", _("No bridge node in xml document")); goto cleanup; } - if ((if_node = virXPathNode("./bridge/interface[2]", ctxt))) { + if (virXPathNode("./bridge/interface[2]", ctxt) != NULL) { vshError(ctl, "%s", _("Multiple interfaces attached to bridge")); goto cleanup; } -- 1.7.11.7

Commit id ac1c77f0 removed the "os" field in "parallelsDomObj" that commit id aa296e6c had added and the data is not used by the function. --- src/parallels/parallels_driver.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 6f33080..2c26730 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -814,9 +814,6 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) if (!(pdom->home = strdup(tmp))) goto no_memory; - if (!(tmp = virJSONValueObjectGetString(jobj, "OS"))) - goto cleanup; - if (!(state = virJSONValueObjectGetString(jobj, "State"))) { parallelsParseError(); goto cleanup; -- 1.7.11.7

On 01/15/13 19:38, John Ferlan wrote:
This patch resolves "UNUSED_VALUE (CWE-563)" errors found by Coverity.
John Ferlan (4): locking: Remove unnecessary setting of lockspace util: Remove the unused setting of 'res' for virHashLookup return virsh: Remove unused setting of 'br_node' and 'if_node' parallels: Remove unused JSON fetch of "OS"
src/locking/lock_daemon_dispatch.c | 4 ++-- src/parallels/parallels_driver.c | 3 --- src/util/virlockspace.c | 6 ++---- tools/virsh-interface.c | 6 +++--- 4 files changed, 7 insertions(+), 12 deletions(-)
ACK series. Peter

On 01/15/13 23:02, Peter Krempa wrote:
On 01/15/13 19:38, John Ferlan wrote:
This patch resolves "UNUSED_VALUE (CWE-563)" errors found by Coverity.
John Ferlan (4): locking: Remove unnecessary setting of lockspace util: Remove the unused setting of 'res' for virHashLookup return virsh: Remove unused setting of 'br_node' and 'if_node' parallels: Remove unused JSON fetch of "OS"
src/locking/lock_daemon_dispatch.c | 4 ++-- src/parallels/parallels_driver.c | 3 --- src/util/virlockspace.c | 6 ++---- tools/virsh-interface.c | 6 +++--- 4 files changed, 7 insertions(+), 12 deletions(-)
ACK series.
and pushed now.
Peter
participants (2)
-
John Ferlan
-
Peter Krempa