From: Thomas Huth <thuth@redhat.com>
To: Alistair Francis <Alistair.Francis@wdc.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
"riku.voipio@iki.fi" <riku.voipio@iki.fi>,
"laurent@vivier.eu" <laurent@vivier.eu>,
"kraxel@redhat.com" <kraxel@redhat.com>,
"alistair23@gmail.com" <alistair23@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v2 3/5] hw/usb/dev-mtp: Fix GCC 9 build warning
Date: Wed, 1 May 2019 09:12:35 +0200 [thread overview]
Message-ID: <e552115b-8fc2-1ff7-dc17-78d949b7f030@redhat.com> (raw)
In-Reply-To: <aeb0e851e027a591eaba99c175011158b1012876.1556666645.git.alistair.francis@wdc.com>
On 01/05/2019 01.28, 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..8233beacab 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 unaligned, 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
Would it be possible to use an assert() instead? Something like
g_assert((dataset->filename & 1) == 0)
?
Thomas
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Huth <thuth@redhat.com>
To: Alistair Francis <Alistair.Francis@wdc.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
"alistair23@gmail.com" <alistair23@gmail.com>,
"riku.voipio@iki.fi" <riku.voipio@iki.fi>,
"laurent@vivier.eu" <laurent@vivier.eu>,
"kraxel@redhat.com" <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 3/5] hw/usb/dev-mtp: Fix GCC 9 build warning
Date: Wed, 1 May 2019 09:12:35 +0200 [thread overview]
Message-ID: <e552115b-8fc2-1ff7-dc17-78d949b7f030@redhat.com> (raw)
Message-ID: <20190501071235.wkTX_fLOUrcO7GlPWqHVZew1nWQs4bIZGs6Q0FJvekI@z> (raw)
In-Reply-To: <aeb0e851e027a591eaba99c175011158b1012876.1556666645.git.alistair.francis@wdc.com>
On 01/05/2019 01.28, 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..8233beacab 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 unaligned, 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
Would it be possible to use an assert() instead? Something like
g_assert((dataset->filename & 1) == 0)
?
Thomas
next prev parent reply other threads:[~2019-05-01 7:12 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-30 23:28 [Qemu-devel] [PATCH v2 0/5] Fix some GCC 9 build warnings Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 1/5] util/qemu-sockets: Fix " Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 9:35 ` Laurent Vivier
2019-05-01 9:35 ` Laurent Vivier
2019-05-01 9:41 ` Daniel P. Berrangé
2019-05-01 9:41 ` Daniel P. Berrangé
2019-05-02 17:57 ` Alistair Francis
2019-05-02 17:57 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 2/5] hw/usb/hcd-xhci: Fix GCC 9 build warning Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 9:37 ` Laurent Vivier
2019-05-01 9:37 ` Laurent Vivier
2019-05-01 9:43 ` Daniel P. Berrangé
2019-05-01 9:43 ` Daniel P. Berrangé
2019-05-01 14:12 ` Richard Henderson
2019-05-01 14:12 ` Richard Henderson
2019-05-01 15:21 ` Philippe Mathieu-Daudé
2019-05-01 15:21 ` Philippe Mathieu-Daudé
2019-05-02 17:53 ` Alistair Francis
2019-05-02 17:53 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 3/5] hw/usb/dev-mtp: " Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 7:12 ` Thomas Huth [this message]
2019-05-01 7:12 ` Thomas Huth
2019-05-01 9:40 ` Daniel P. Berrangé
2019-05-01 9:40 ` Daniel P. Berrangé
2019-05-02 17:48 ` Alistair Francis
2019-05-02 17:48 ` Alistair Francis
2019-04-30 23:28 ` [Qemu-devel] [PATCH v2 4/5] linux-user/uname: Fix GCC 9 build warnings Alistair Francis
2019-04-30 23:28 ` Alistair Francis
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 9:44 ` Daniel P. Berrangé
2019-05-01 9:44 ` Daniel P. Berrangé
2019-05-01 9:46 ` Laurent Vivier
2019-05-01 9:46 ` Laurent Vivier
2019-05-01 12:00 ` Eric Blake
2019-05-01 12:00 ` Eric Blake
2019-05-02 17:24 ` Alistair Francis
2019-05-02 17:24 ` Alistair Francis
2019-04-30 23:29 ` [Qemu-devel] [PATCH v2 5/5] linux-user/elfload: " Alistair Francis
2019-04-30 23:29 ` Alistair Francis
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 9:40 ` Laurent Vivier
2019-05-01 14:15 ` Richard Henderson
2019-05-01 14:15 ` Richard Henderson
2019-05-02 8:14 ` Laurent Vivier
2019-05-02 8:14 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e552115b-8fc2-1ff7-dc17-78d949b7f030@redhat.com \
--to=thuth@redhat.com \
--cc=Alistair.Francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=kraxel@redhat.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).