<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 4, 2015 at 7:58 PM, Zbigniew Jędrzejewski-Szmek <span dir="ltr"><<a href="mailto:zbyszek@in.waw.pl" target="_blank">zbyszek@in.waw.pl</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 Tue, Mar 03, 2015 at 04:21:30PM -0800, Shawn Landden wrote:<br>
> also switch to <inttypes.h><br>
> ---<br>
> src/udev/udev-builtin-usb_id.c | 35 ++++++++++++++++++-----------------<br>
> 1 file changed, 18 insertions(+), 17 deletions(-)<br>
><br>
> diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c<br>
> index ab0d96e..0223421 100644<br>
> --- a/src/udev/udev-builtin-usb_id.c<br>
> +++ b/src/udev/udev-builtin-usb_id.c<br>
> @@ -28,6 +28,7 @@<br>
> #include <ctype.h><br>
> #include <fcntl.h><br>
> #include <errno.h><br>
> +#include <inttypes.h><br>
><br>
> #include "udev.h"<br>
><br>
> @@ -153,15 +154,15 @@ static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len<br>
> int pos = 0;<br>
> unsigned strpos = 0;<br>
> struct usb_interface_descriptor {<br>
> - u_int8_t bLength;<br>
> - u_int8_t bDescriptorType;<br>
> - u_int8_t bInterfaceNumber;<br>
> - u_int8_t bAlternateSetting;<br>
> - u_int8_t bNumEndpoints;<br>
> - u_int8_t bInterfaceClass;<br>
> - u_int8_t bInterfaceSubClass;<br>
> - u_int8_t bInterfaceProtocol;<br>
> - u_int8_t iInterface;<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>
</div></div>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></blockquote><div>Common misunderstanding about strict aliasing. if accessing as char * yes, but not the other way around. See the C11 standard which makes it clear (don't have page number off the top of my head...) </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[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>
Zbyszek<br>
_______________________________________________<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>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Shawn Landden</div>
</div></div>