[PATCH 3/7] virsh-domain-monitor: Resolve Coverity issues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recent changes uncovered a pair of NEGATIVE_RETURNS when processing the
'nnames' in 'vshDomainListCollect' in the for loop due to possible -1 value.
---
 tools/virsh-domain-monitor.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 7af765e..bd853ba 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1399,6 +1399,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
     vshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
     size_t i;
     int ret;
+    int rc;
     int *ids = NULL;
     int nids = 0;
     char **names = NULL;
@@ -1467,16 +1468,17 @@ fallback:
 
     if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
         VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE)) {
-        if ((nnames = virConnectNumOfDefinedDomains(ctl->conn)) < 0) {
+        if ((rc = virConnectNumOfDefinedDomains(ctl->conn)) < 0) {
             vshError(ctl, "%s", _("Failed to list inactive domains"));
             goto cleanup;
         }
 
-        if (nnames) {
+        if (rc) {
+            nnames = rc;
             names = vshMalloc(ctl, sizeof(char *) * nnames);
 
-            if ((nnames = virConnectListDefinedDomains(ctl->conn, names,
-                                                      nnames)) < 0) {
+            if ((rc = virConnectListDefinedDomains(ctl->conn, names,
+                                                   nnames)) < 0) {
                 vshError(ctl, "%s", _("Failed to list inactive domains"));
                 goto cleanup;
             }
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]