Skip to contentSkip to conversation

ui: fix format specifier in vnc_client_io_error() to avoid break in build.

PATCH Superseded Rami Rosen 2 participants 2 messages Jan 8, 2017 – Jan 9, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Rami Rosen

author
#0 lore raw

PATCH 1/1 ui: fix format specifier in vnc_client_io_error() to avoid break in build.

When building qemu after setting _VNC_DEBUG to 1 (see ui/vnc.h),
we get the following error and the build breaks:
...
ui/vnc.c: In function ‘vnc_client_io_error’:
ui/vnc.c:1262:13: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ [-Werror=format=]
VNC_DEBUG("Closing down client sock: ret %d (%s)\n",
^
cc1: all warnings being treated as errors
make: *** [ui/vnc.o] Error 1
...

This patch solves this issue by fixing the print format specifier in vnc_client_io_error() to be %ld, which corresponds to the type of the "ret" variable.

---
 ui/vnc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ui/vnc.c +1 -1
index 2c28a59..4b0a89c 100644
@@ -1259,7 +1259,7 @@ ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp)
         if (ret == 0) {
             VNC_DEBUG("Closing down client sock: EOF\n");
         } else if (ret != QIO_CHANNEL_ERR_BLOCK) {
-            VNC_DEBUG("Closing down client sock: ret %d (%s)\n",
+            VNC_DEBUG("Closing down client sock: ret %ld (%s)\n",
                       ret, errp ? error_get_pretty(*errp) : "Unknown");
         }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 11 lines · Rami Rosen

When building qemu after setting _VNC_DEBUG to 1 (see ui/vnc.h),
we get the following error and the build breaks:
...
ui/vnc.c: In function ‘vnc_client_io_error’:
ui/vnc.c:1262:13: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ [-Werror=format=]
VNC_DEBUG("Closing down client sock: ret %d (%s)\n",
^
cc1: all warnings being treated as errors
make: *** [ui/vnc.o] Error 1
...

Quoted 3 lines

This patch solves this issue by fixing the print format specifier in vnc_client_io_error() to be %ld, which corresponds to the type of the "ret" variable.

NACK. "ret" is ssize_t, which might be 'long' on some platforms, but is 'int' on others (32-bit platforms come to mind).

Quoted 11 lines
---
 ui/vnc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ui/vnc.c +0 -0
index 2c28a59..4b0a89c 100644

ui/vnc.c ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp) · line 1262

Quoted 5 lines
ui/vnc.c +1 -1
@@ -1259,7 +1259,7 @@ ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp)
         if (ret == 0) {
             VNC_DEBUG("Closing down client sock: EOF\n");
         } else if (ret != QIO_CHANNEL_ERR_BLOCK) {
-            VNC_DEBUG("Closing down client sock: ret %d (%s)\n",
+            VNC_DEBUG("Closing down client sock: ret %ld (%s)\n",

%zd is better than %ld. Note that %zd is technically undefined - neither C nor POSIX requires that the signed counterpart to 'size_t' be ssize_t, nor that 'ssize_t' be the same size as 'size_t'; but it is safe enough in qemu as we already have plenty of existing uses of this idiom (and any platform that implements 'ssize_t' in a way that doesn't match '%zd' is stupid when it comes to quality-of-implementation).

Looking forward to v2.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org