[libvirt] [PATCH] virtlogd: use PRIu64 to print 64bit types

Otherwise we fail on 32bit with: CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 3 ++- tests/virrotatingfiletest.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c index 269255a..7391a6f 100644 --- a/src/logging/log_daemon_dispatch.c +++ b/src/logging/log_daemon_dispatch.c @@ -21,6 +21,7 @@ */ #include <config.h> +#include <inttypes.h> #include "rpc/virnetserver.h" #include "rpc/virnetserverclient.h" @@ -118,7 +119,7 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_ if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Requested data len %zu is larger than maximum %d"), + _("Requested data len %"PRIu64" is larger than maximum %d"), args->maxlen, VIR_LOG_MANAGER_PROTOCOL_STRING_MAX); goto cleanup; } diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c index ed55e63..73f0c26 100644 --- a/tests/virrotatingfiletest.c +++ b/tests/virrotatingfiletest.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <unistd.h> #include <fcntl.h> +#include <inttypes.h> #include "virrotatingfile.h" #include "virlog.h" @@ -57,7 +58,8 @@ static int testRotatingFileWriterAssertOneFileSize(const char *filename, fprintf(stderr, "File %s should not exist\n", filename); return -1; } else if (sb.st_size != size) { - fprintf(stderr, "File %s should be %zu bytes not %zu\n", + fprintf(stderr, "File %s should be %" PRIu64 + " bytes not %" PRIu64 "\n", filename, size, sb.st_size); return -1; } else { -- 2.6.2

On Thu, Nov 26, 2015 at 06:46:13PM +0100, Guido Günther wrote:
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 3 ++- tests/virrotatingfiletest.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c index 269255a..7391a6f 100644 --- a/src/logging/log_daemon_dispatch.c +++ b/src/logging/log_daemon_dispatch.c @@ -21,6 +21,7 @@ */
#include <config.h> +#include <inttypes.h>
#include "rpc/virnetserver.h" #include "rpc/virnetserverclient.h" @@ -118,7 +119,7 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_
if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Requested data len %zu is larger than maximum %d"), + _("Requested data len %"PRIu64" is larger than maximum %d"),
We don't ever use PRIu64 in libvirt - gnulib guarantees that %llu and %lld are always used for formatting 64bit ints. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Nov 26, 2015 at 05:52:11PM +0000, Daniel P. Berrange wrote:
On Thu, Nov 26, 2015 at 06:46:13PM +0100, Guido Günther wrote:
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 3 ++- tests/virrotatingfiletest.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c index 269255a..7391a6f 100644 --- a/src/logging/log_daemon_dispatch.c +++ b/src/logging/log_daemon_dispatch.c @@ -21,6 +21,7 @@ */
#include <config.h> +#include <inttypes.h>
#include "rpc/virnetserver.h" #include "rpc/virnetserverclient.h" @@ -118,7 +119,7 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_
if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Requested data len %zu is larger than maximum %d"), + _("Requested data len %"PRIu64" is larger than maximum %d"),
We don't ever use PRIu64 in libvirt - gnulib guarantees that %llu and %lld are always used for formatting 64bit ints.
But with %llu I get on 64bit: make[3]: Entering directory '/var/scratch/src/libvirt/upstream/libvirt/src' CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:8: error: format '%llu' expects argument of type 'long long unsigned int', but argument 7 has type 'uint64_t {aka long unsigned int}' [-Werror=format=] virReportError(VIR_ERR_INTERNAL_ERROR, ^ cc1: all warnings being treated as errors Puzzled, -- Guido

On Thu, Nov 26, 2015 at 07:13:40PM +0100, Guido Günther wrote:
On Thu, Nov 26, 2015 at 05:52:11PM +0000, Daniel P. Berrange wrote:
On Thu, Nov 26, 2015 at 06:46:13PM +0100, Guido Günther wrote:
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 3 ++- tests/virrotatingfiletest.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c index 269255a..7391a6f 100644 --- a/src/logging/log_daemon_dispatch.c +++ b/src/logging/log_daemon_dispatch.c @@ -21,6 +21,7 @@ */
#include <config.h> +#include <inttypes.h>
#include "rpc/virnetserver.h" #include "rpc/virnetserverclient.h" @@ -118,7 +119,7 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_
if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Requested data len %zu is larger than maximum %d"), + _("Requested data len %"PRIu64" is larger than maximum %d"),
We don't ever use PRIu64 in libvirt - gnulib guarantees that %llu and %lld are always used for formatting 64bit ints.
But with %llu I get on 64bit:
make[3]: Entering directory '/var/scratch/src/libvirt/upstream/libvirt/src' CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:8: error: format '%llu' expects argument of type 'long long unsigned int', but argument 7 has type 'uint64_t {aka long unsigned int}' [-Werror=format=] virReportError(VIR_ERR_INTERNAL_ERROR, ^ cc1: all warnings being treated as errors
Oh that's just a stupid compiler not realizing the two types are in fact the same size. Just cast the arg to (unsigned long long) for this. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Otherwise we fail on 32bit with: CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 5 +++-- tests/virrotatingfiletest.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c index 269255a..160ab00 100644 --- a/src/logging/log_daemon_dispatch.c +++ b/src/logging/log_daemon_dispatch.c @@ -118,8 +118,9 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_ if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Requested data len %zu is larger than maximum %d"), - args->maxlen, VIR_LOG_MANAGER_PROTOCOL_STRING_MAX); + _("Requested data len %llu is larger than maximum %d"), + (unsigned long long)args->maxlen, + VIR_LOG_MANAGER_PROTOCOL_STRING_MAX); goto cleanup; } diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c index ed55e63..03e9664 100644 --- a/tests/virrotatingfiletest.c +++ b/tests/virrotatingfiletest.c @@ -57,8 +57,9 @@ static int testRotatingFileWriterAssertOneFileSize(const char *filename, fprintf(stderr, "File %s should not exist\n", filename); return -1; } else if (sb.st_size != size) { - fprintf(stderr, "File %s should be %zu bytes not %zu\n", - filename, size, sb.st_size); + fprintf(stderr, "File %s should be %llu bytes not %llu\n", + filename, (unsigned long long)size, + (unsigned long long)sb.st_size); return -1; } else { return 0; -- 2.6.2

On Thu, Nov 26, 2015 at 07:33:38PM +0100, Guido Günther wrote:
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 5 +++-- tests/virrotatingfiletest.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Nov 26, 2015 at 06:36:10PM +0000, Daniel P. Berrange wrote:
On Thu, Nov 26, 2015 at 07:33:38PM +0100, Guido Günther wrote:
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile': logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format] --- src/logging/log_daemon_dispatch.c | 5 +++-- tests/virrotatingfiletest.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
ACK
Pushed. Sorry for the lengthy thread for such a tiny change. -- Guido
participants (2)
-
Daniel P. Berrange
-
Guido Günther