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

Re: [libvirt] [PATCH] build: avoid type-punning in vbox



Am 20. April 2012 01:36 schrieb Eric Blake <eblake redhat com>:
> Commit 78345c68 makes at least gcc 4.1.2 on RHEL 5 complain:
>
> cc1: warnings being treated as errors
> In file included from vbox/vbox_V4_0.c:13:
> vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags':
> vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>
> * src/vbox/vbox_tmpl.c (vboxDomainUndefineFlags): Use union to
> avoid compiler warning.
> ---
>
> Pushing this under the build-breaker rule.
>
>  src/vbox/vbox_tmpl.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
> index be25828..57c18a4 100644
> --- a/src/vbox/vbox_tmpl.c
> +++ b/src/vbox/vbox_tmpl.c
> @@ -5294,8 +5294,11 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
>
>         ((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress);
>  # else
> -        vboxArray array = VBOX_ARRAY_INITIALIZER;
> -        machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress);
> +        union {
> +            vboxArray array;
> +            IMedium *medium;
> +        } u = { .array = VBOX_ARRAY_INITIALIZER };
> +        machine->vtbl->Delete(machine, 0, &u.medium, &progress);
>  # endif
>         if (progress != NULL) {
>             progress->vtbl->WaitForCompletion(progress, -1);

Actually, NACK. As stated in the other mail, vboxArray is not castable
to IMedium*. True, it silences the compiler any might even work by
accident on XPCOM because VirtualBox might not touch the pointer
beyond checking it for being non-NULL because the 0 tells it that it's
an empty array. But still this is wrong and might crash on MSCOM.

I might come up with a proper solution tomorrow.

-- 
Matthias Bolte
http://photron.blogspot.com


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