The simple way out is to use ALIGNED_CAST instead. diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 04dd048..cc19db4 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -4189,7 +4189,8 @@ parse_ENCAP(char *arg, return error; } /* ofbuf out may have been re-allocated. */ - encap = (struct ofpact_encap *) ((char *)out->data + start_ofs); + encap = ALIGNED_CAST(struct ofpact_encap *, (char *)out->data + start_ofs); encap->n_props = n_props; ofpact_finish_ENCAP(out, &encap); return NULL; @@ -4224,7 +4225,7 @@ format_ed_props(struct ds *s, uint16_t n_props, format_ed_prop_value(s, prop); ds_put_cstr(s, ")"); p += ROUND_UP(prop->len, 8); - prop = (const struct ofpact_ed_prop *) p; + prop = ALIGNED_CAST(const struct ofpact_ed_prop *, p); } }
While I'm sure this is correct for the second case, I don't understand enough of the ofpbuf implementation to be certain that the buffer has the same alignment after a re-allocation. If that was guaranteed, the ALIGNED_CAST should be safe as the start_ofs does not change. /Jan > -----Original Message----- > From: Ben Pfaff [mailto:b...@ovn.org] > Sent: Thursday, 13 July, 2017 19:22 > To: Zoltán Balogh <zoltan.bal...@ericsson.com> > Cc: 'd...@openvswitch.org' <d...@openvswitch.org>; Jan Scheurich > <jan.scheur...@ericsson.com>; Georg Schmuecking > <georg.schmueck...@ericsson.com>; Jiri Benc (jb...@redhat.com) > <jb...@redhat.com>; Yang, Yi Y <yi.y.y...@intel.com> > Subject: Re: [PATCH 1/4] Add OF actions for generic encap and decap > > On Thu, Jul 13, 2017 at 04:49:09PM +0000, Zoltán Balogh wrote: > > Hello Ben, > > > > > > > GCC says: > > > > > > ../lib/ofp-actions.c:4189:13: error: cast from 'char *' to 'struct > > > ofpact_encap *' increases required alignment > > > from 1 to 4 [-Werror,-Wcast-align] > > > ../lib/ofp-actions.c:4222:16: error: cast from 'const uint8_t *' (aka > > > 'const unsigned char *') to 'const struct > > > ofpact_ed_prop *' increases required alignment from 1 to 2 > > > [-Werror,-Wcast-align] > > > > I cannot see these errors. I've tested with GCC 4.8.4 on Ubuntu 14.04.5 LTS > > and with GCC 6.3.0 on Ubuntu 17.04. > > Which version of GCC and Linux distro did you use? Did you pass any special > > args to make or to the configure script? > > It might be specific to 32-bit builds, since I build and test on i386. _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev