[libvirt] [PATCH] build: fix type-punning bug

With older gcc and 64-bit size_t, the compiler issues a real warning: rpc/virnetserverservice.c:277: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] Introduced in commit 0cc79255. Depending on machine endianness, this warning represents a real bug that could mis-interpret the value by a factor of 2^32. I don't know why newer gcc didn't bother to warn. * src/rpc/virnetserverservice.c (virNetServerServiceNewPostExecRestart): Use temporary instead. --- src/rpc/virnetserverservice.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 8ac523c..31a9424 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -1,7 +1,7 @@ /* * virnetserverservice.c: generic network RPC server service * - * Copyright (C) 2006-2011 Red Hat, Inc. + * Copyright (C) 2006-2012 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -274,11 +274,12 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj goto error; } if (virJSONValueObjectGetNumberUint(object, "nrequests_client_max", - (unsigned int *)&svc->nrequests_client_max) < 0) { + &n) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing nrequests_client_max field in JSON state document")); goto error; } + svc->nrequests_client_max = n; if (!(socks = virJSONValueObjectGet(object, "socks"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", -- 1.7.11.7

On 10/26/2012 12:58 PM, Eric Blake wrote:
With older gcc and 64-bit size_t, the compiler issues a real warning: rpc/virnetserverservice.c:277: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
Introduced in commit 0cc79255. Depending on machine endianness, this warning represents a real bug that could mis-interpret the value by a factor of 2^32. I don't know why newer gcc didn't bother to warn.
* src/rpc/virnetserverservice.c (virNetServerServiceNewPostExecRestart): Use temporary instead. --- src/rpc/virnetserverservice.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Pushed under the build-breaker rule. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Commit 246143b fixed a warning on older gcc, but caused a warning on newer gcc. ../../src/rpc/virnetserverservice.c: In function 'virNetServerServiceNewPostExecRestart': ../../src/rpc/virnetserverservice.c:277:41: error: pointer targets in passing argument 3 of 'virJSONValueObjectGetNumberUint' differ in signedness [-Werror=pointer-sign] * src/rpc/virnetserverservice.c: Use correct types. --- Pushing under the build-breaker rule, again. Gah - sometimes I need to slow down and test patches on more than one machine before pushing. Sorry for today's churn. src/rpc/virnetserverservice.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 31a9424..a9362ad 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -256,6 +256,7 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj virJSONValuePtr socks; size_t i; int n; + unsigned int max; if (virNetServerServiceInitialize() < 0) return NULL; @@ -274,12 +275,12 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj goto error; } if (virJSONValueObjectGetNumberUint(object, "nrequests_client_max", - &n) < 0) { + &max) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing nrequests_client_max field in JSON state document")); goto error; } - svc->nrequests_client_max = n; + svc->nrequests_client_max = max; if (!(socks = virJSONValueObjectGet(object, "socks"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", -- 1.7.11.7
participants (1)
-
Eric Blake