<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 8, 2015 at 4:11 PM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, 05.03.15 04:58, Zbigniew Jędrzejewski-Szmek (<a href="mailto:zbyszek@in.waw.pl">zbyszek@in.waw.pl</a>) wrote:<br>
<br>
> > +                uint8_t        bLength;<br>
> > +                uint8_t        bDescriptorType;<br>
> > +                uint8_t        bInterfaceNumber;<br>
> > +                uint8_t        bAlternateSetting;<br>
> > +                uint8_t        bNumEndpoints;<br>
> > +                uint8_t        bInterfaceClass;<br>
> > +                uint8_t        bInterfaceSubClass;<br>
> > +                uint8_t        bInterfaceProtocol;<br>
> > +                uint8_t        iInterface;<br>
> >          } __attribute__((packed));<br>
> ><br>
> >          if (asprintf(&filename, "%s/descriptors", udev_device_get_syspath(dev)) < 0)<br>
> > @@ -179,21 +180,21 @@ static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len<br>
> ><br>
> >          ifs_str[0] = '\0';<br>
> >          while (pos < size && strpos+7 < len-2) {<br>
> > -                struct usb_interface_descriptor *desc;<br>
> > +                struct usb_interface_descriptor desc;<br>
> >                  char if_str[8];<br>
> ><br>
> > -                desc = (struct usb_interface_descriptor *) &buf[pos];<br>
> > -                if (desc->bLength < 3)<br>
> > +                memcpy(&desc, &buf[pos], sizeof(desc));<br>
> Copying it seems suboptimal. But is this actually an aliasing<br>
> violation? buf is a char array, and [1] says: "a character type<br>
> may alias any other type".<br>
><br>
> [1] <a href="https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Optimize-Options.html#index-fstrict_002daliasing-825" target="_blank">https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Optimize-Options.html#index-fstrict_002daliasing-825</a><br>
<br>
</div></div>Also, I greatly prefer using unions for these things, to make the<br>
aliasing explicit, rather than copying things.<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div>The other solution I had was to use offsetof() to basically make it an enum, but that made the code was quite a bit more verbose. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">
Lennart<br>
<br>
--<br>
Lennart Poettering, Red Hat<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Shawn Landden</div>
</div></div>