[PATCH] virsh: avoid compiler warning on mingw

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

 



We don't use gnulib's sanitizations for vfprintf, but vshDebug
was used with %zu, which means that it would fail on mingw.
Thank goodness the compiler indirectly caught this for us :)

virsh.c: In function 'vshDebug':
virsh.c:12105:5: warning: function might be possible candidate for
'ms_printf' format attribute [-Wmissing-format-attribute]

since mingw <stdio.h> hasn't yet added gcc attributes to vfprintf.

* tools/virsh.c (vshDebug): Avoid vfprintf.
(vshPrintExtra): Use lighter-weight fputs.
Reported by Matthias Bolte.
---
 tools/virsh.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 27140f3..0212b99 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12096,6 +12096,7 @@ static void
 vshDebug(vshControl *ctl, int level, const char *format, ...)
 {
     va_list ap;
+    char *str;

     va_start(ap, format);
     vshOutputLogFile(ctl, VSH_ERR_DEBUG, format, ap);
@@ -12105,8 +12106,14 @@ vshDebug(vshControl *ctl, int level, const char *format, ...)
         return;

     va_start(ap, format);
-    vfprintf(stdout, format, ap);
+    if (virVasprintf(&str, format, ap) < 0) {
+        /* Skip debug messages on low memory */
+        va_end(ap);
+        return;
+    }
     va_end(ap);
+    fputs(str, stdout);
+    VIR_FREE(str);
 }

 static void
@@ -12125,7 +12132,7 @@ vshPrintExtra(vshControl *ctl, const char *format, ...)
         return;
     }
     va_end(ap);
-    fprintf(stdout, "%s", str);
+    fputs(str, stdout);
     VIR_FREE(str);
 }

-- 
1.7.4.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]