diff mbox

[ovs-dev,1/4] Add OF actions for generic encap and decap

Message ID CFF8EF42F1132E4CBE2BF0AB6C21C58D6E541C52@ESESSMB107.ericsson.se
State Not Applicable
Headers show

Commit Message

Jan Scheurich July 13, 2017, 5:34 p.m. UTC
The simple way out is to use ALIGNED_CAST instead.

         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:blp@ovn.org]
> Sent: Thursday, 13 July, 2017 19:22
> To: Zoltán Balogh <zoltan.balogh@ericsson.com>
> Cc: 'dev@openvswitch.org' <dev@openvswitch.org>; Jan Scheurich <jan.scheurich@ericsson.com>; Georg Schmuecking
> <Georg.Schmuecking@ericsson.com>; Jiri Benc (jbenc@redhat.com) <jbenc@redhat.com>; Yang, Yi Y <yi.y.yang@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.
diff mbox

Patch

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,