With new gcc9 how to handle error from -Werror=address-of-packed-member

Segher Boessenkool segher@kernel.crashing.org
Thu Feb 14 13:59:00 GMT 2019


On Thu, Feb 14, 2019 at 11:46:49AM +0100, Normand wrote:
> On 14/02/2019 11:10, Florian Weimer wrote:
> >>With new gcc9 there are new error reported by
> >>-Werror=address-of-packed-member
> >>How to handle such error ?
> >>
> >>eg:
> >>libflash/ecc.c:419:24: error: taking address of packed member of
> >>'struct ecc64' may result in an unaligned pointer value
> >>[-Werror=address-of-packed-member]
> >>   419 |   memcpy(inc_uint64_by(&ecc_word.data, alignment), src,
> >>bytes_wanted);
> >>       |                        ^~~~~~~~~~~~~~
> >
> >What does the definition of struct ecc64 look like?
> 
> Florian, the related struct is:
> struct ecc64 {
> 	beint64_t data;
> 	uint8_t ecc;
> } __attribute__((__packed__));

You could use &ecc_word instead of &ecc_word.data on that line 419.  Or,
rewrite this code so it is more understandable and more obviously correct.


Segher



More information about the Gcc-help mailing list