Fix this warning with GCC 9 on Fedora 30:
hw/usb/dev-mtp.c:1715:36: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
1715 | dataset->filename);
| ~~~~~~~^~~~~~~~~~
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
hw/usb/dev-mtp.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 99548b012d..6de85d99e6 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1711,9 +1711,22 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen)
assert(!s->write_pending);
assert(p != NULL);
+/*
+ * We are about to access a packed struct. We are confident that the pointer
+ * address won't be unalligned, so we ignore GCC warnings.
+ */
+#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+#endif
+
filename = utf16_to_str(MIN(dataset->length, filename_chars),
dataset->filename);
+#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
+#pragma GCC diagnostic pop
+#endif
+
if (strchr(filename, '/')) {
usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
0, 0, 0, 0);
--
2.21.0
Le 30/04/2019 à 22:09, Alistair Francis a écrit :
> Fix this warning with GCC 9 on Fedora 30:
> hw/usb/dev-mtp.c:1715:36: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
> 1715 | dataset->filename);
> | ~~~~~~~^~~~~~~~~~
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/usb/dev-mtp.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> index 99548b012d..6de85d99e6 100644
> --- a/hw/usb/dev-mtp.c
> +++ b/hw/usb/dev-mtp.c
> @@ -1711,9 +1711,22 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen)
> assert(!s->write_pending);
> assert(p != NULL);
>
> +/*
> + * We are about to access a packed struct. We are confident that the pointer
> + * address won't be unalligned, so we ignore GCC warnings.
> + */
> +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
> +#endif
> +
> filename = utf16_to_str(MIN(dataset->length, filename_chars),
> dataset->filename);
>
> +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> +#pragma GCC diagnostic pop
> +#endif
> +
> if (strchr(filename, '/')) {
> usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
> 0, 0, 0, 0);
>
You should move and use PRAGMA_DISABLE_PACKED_WARNING and
PRAGMA_REENABLE_PACKED_WARNING from linux-user/qemu.h.
It has laready been very well tested :)
Thanks,
Laurent
Le 30/04/2019 à 22:28, Laurent Vivier a écrit :
> Le 30/04/2019 à 22:09, Alistair Francis a écrit :
>> Fix this warning with GCC 9 on Fedora 30:
>> hw/usb/dev-mtp.c:1715:36: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
>> 1715 | dataset->filename);
>> | ~~~~~~~^~~~~~~~~~
>>
>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>> ---
>> hw/usb/dev-mtp.c | 13 +++++++++++++
>> 1 file changed, 13 insertions(+)
>>
>> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
>> index 99548b012d..6de85d99e6 100644
>> --- a/hw/usb/dev-mtp.c
>> +++ b/hw/usb/dev-mtp.c
>> @@ -1711,9 +1711,22 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen)
>> assert(!s->write_pending);
>> assert(p != NULL);
>>
>> +/*
>> + * We are about to access a packed struct. We are confident that the pointer
>> + * address won't be unalligned, so we ignore GCC warnings.
>> + */
>> +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
>> +#pragma GCC diagnostic push
>> +#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
>> +#endif
>> +
>> filename = utf16_to_str(MIN(dataset->length, filename_chars),
>> dataset->filename);
>>
>> +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
>> +#pragma GCC diagnostic pop
>> +#endif
>> +
>> if (strchr(filename, '/')) {
>> usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
>> 0, 0, 0, 0);
>>
>
> You should move and use PRAGMA_DISABLE_PACKED_WARNING and
> PRAGMA_REENABLE_PACKED_WARNING from linux-user/qemu.h.
>
> It has laready been very well tested :)
Oh, they are for clang and a false positive, so forget my comment (and
the following one)
Thanks,
Laurent
On 4/30/19 3:09 PM, Alistair Francis wrote:
> Fix this warning with GCC 9 on Fedora 30:
> hw/usb/dev-mtp.c:1715:36: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
> 1715 | dataset->filename);
> | ~~~~~~~^~~~~~~~~~
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/usb/dev-mtp.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> index 99548b012d..6de85d99e6 100644
> --- a/hw/usb/dev-mtp.c
> +++ b/hw/usb/dev-mtp.c
> @@ -1711,9 +1711,22 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen)
> assert(!s->write_pending);
> assert(p != NULL);
>
> +/*
> + * We are about to access a packed struct. We are confident that the pointer
> + * address won't be unalligned, so we ignore GCC warnings.
unaligned
Aren't there other potential proposed patches floating around for this
issue that do not involve messing with pragmas?
> + */
> +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
> +#endif
> +
> filename = utf16_to_str(MIN(dataset->length, filename_chars),
> dataset->filename);
>
> +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> +#pragma GCC diagnostic pop
> +#endif
> +
> if (strchr(filename, '/')) {
> usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
> 0, 0, 0, 0);
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
On Tue, Apr 30, 2019 at 1:37 PM Eric Blake <eblake@redhat.com> wrote:
>
> On 4/30/19 3:09 PM, Alistair Francis wrote:
> > Fix this warning with GCC 9 on Fedora 30:
> > hw/usb/dev-mtp.c:1715:36: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
> > 1715 | dataset->filename);
> > | ~~~~~~~^~~~~~~~~~
> >
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> > hw/usb/dev-mtp.c | 13 +++++++++++++
> > 1 file changed, 13 insertions(+)
> >
> > diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> > index 99548b012d..6de85d99e6 100644
> > --- a/hw/usb/dev-mtp.c
> > +++ b/hw/usb/dev-mtp.c
> > @@ -1711,9 +1711,22 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen)
> > assert(!s->write_pending);
> > assert(p != NULL);
> >
> > +/*
> > + * We are about to access a packed struct. We are confident that the pointer
> > + * address won't be unalligned, so we ignore GCC warnings.
>
> unaligned
Fixed.
>
> Aren't there other potential proposed patches floating around for this
> issue that do not involve messing with pragmas?
I'm not sure, I haven't seen anything. I'm more then open to a better
fix, this is the best option I could think of.
Alistair
>
> > + */
> > +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
> > +#endif
> > +
> > filename = utf16_to_str(MIN(dataset->length, filename_chars),
> > dataset->filename);
> >
> > +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> > +#pragma GCC diagnostic pop
> > +#endif
> > +
> > if (strchr(filename, '/')) {
> > usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
> > 0, 0, 0, 0);
> >
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3226
> Virtualization: qemu.org | libvirt.org
>
© 2016 - 2025 Red Hat, Inc.