]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Resolve Coverity BAD_SIZEOF
authorJohn Ferlan <jferlan@redhat.com>
Fri, 12 Sep 2014 12:22:58 +0000 (08:22 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 15 Sep 2014 15:01:32 +0000 (11:01 -0400)
Coverity complains about the calculation of the buf & len within
the PROBE macro.  So to quiet things down, do the calculation prior
to usage in either write() or qemuMonitorIOWriteWithFD() calls and
then have the PROBE use the calculated values - which works.

src/qemu/qemu_monitor.c

index 60591338a4f01b376b78381a9aa7b049456e93bf..89446d702415676bf9279a4d98e6d66cf63962a2 100644 (file)
@@ -478,6 +478,8 @@ static int
 qemuMonitorIOWrite(qemuMonitorPtr mon)
 {
     int done;
+    char *buf;
+    size_t len;
 
     /* If no active message, or fully transmitted, the no-op */
     if (!mon->msg || mon->msg->txOffset == mon->msg->txLength)
@@ -489,22 +491,16 @@ qemuMonitorIOWrite(qemuMonitorPtr mon)
         return -1;
     }
 
+    buf = mon->msg->txBuffer + mon->msg->txOffset;
+    len = mon->msg->txLength - mon->msg->txOffset;
     if (mon->msg->txFD == -1)
-        done = write(mon->fd,
-                     mon->msg->txBuffer + mon->msg->txOffset,
-                     mon->msg->txLength - mon->msg->txOffset);
+        done = write(mon->fd, buf, len);
     else
-        done = qemuMonitorIOWriteWithFD(mon,
-                                        mon->msg->txBuffer + mon->msg->txOffset,
-                                        mon->msg->txLength - mon->msg->txOffset,
-                                        mon->msg->txFD);
+        done = qemuMonitorIOWriteWithFD(mon, buf, len, mon->msg->txFD);
 
     PROBE(QEMU_MONITOR_IO_WRITE,
-          "mon=%p buf=%s len=%d ret=%d errno=%d",
-          mon,
-          mon->msg->txBuffer + mon->msg->txOffset,
-          mon->msg->txLength - mon->msg->txOffset,
-          done, errno);
+          "mon=%p buf=%s len=%lu ret=%d errno=%d",
+          mon, buf, len, done, errno);
 
     if (mon->msg->txFD != -1) {
         PROBE(QEMU_MONITOR_IO_SEND_FD,