[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [qemu-s390x] [PATCH 10/14] usb-mtp: avoid warning about unaligned ac
From: |
Daniel P . Berrangé |
Subject: |
Re: [qemu-s390x] [PATCH 10/14] usb-mtp: avoid warning about unaligned access to filename |
Date: |
Fri, 29 Mar 2019 11:58:27 +0000 |
User-agent: |
Mutt/1.11.3 (2019-02-01) |
On Fri, Mar 29, 2019 at 12:25:54PM +0100, Thomas Huth wrote:
> On 29/03/2019 12.11, Daniel P. Berrangé wrote:
> > The 'filename' field in ObjectInfo struct is declared as a
> > zero length array of uint16_t. Accessing it is equivalent
> > to taking the address of the field, and taking the address
> > of fields in a packed struct causes unaligned pointer
> > warnings:
> >
> > hw/usb/dev-mtp.c: In function ‘usb_mtp_write_metadata’:
> > hw/usb/dev-mtp.c:1712:36: warning: taking address of packed member of
> > ‘struct <anonymous>’ may result in an unaligned pointer value
> > [-Waddress-of-packed-member]
> > 1712 | dataset->filename);
> > | ~~~~~~~^~~~~~~~~~
> >
> > The warning is in fact correct because the 'filename'
> > field is preceeded by a uint8_t field which causes it
> > to have bad alignment.
> >
> > Using pointer arithmetic instead of accessing the zero
> > length array field directly avoids the compiler warning
> > but doesn't ultimately fix the bad alignment. Fixing
> > that probably requires allocating a new array of
> > uint16_t in the heap & then memcpy() the data before
> > accessing the array elements.
>
> If we are really using an unaligned pointer here, this code will crash
> on Sparc host machines (and maybe some others). Thus I'd prefer if you
> could rather fix the misalignment issue here instead of papering over
> the compiler warning.
Yeah, I wasn't sure if uint16 mis-alignment would cause problems or
not in practice, so left this comment in the commit message. If you
expect this really will crash, then I guess we have to go the memcpy
to temporary buffer route.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [qemu-s390x] [PATCH 01/14] target/xtensa: fix break_dependency for repeated resources, (continued)
- [qemu-s390x] [PATCH 01/14] target/xtensa: fix break_dependency for repeated resources, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 02/14] target/xtensa: don't announce exit simcall, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 03/14] tests/tcg/xtensa: clean up test set, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 04/14] linux-user: avoid string truncation warnings in uname field copying, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 05/14] linux-user: avoid string truncation warnings in elf field copying, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 06/14] sockets: avoid string truncation warnings when copying UNIX path, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 07/14] hw/usb: avoid format truncation warning when formatting port name, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 09/14] usb-mtp: fix string length for filename when writing metadata, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 10/14] usb-mtp: avoid warning about unaligned access to filename, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 08/14] qxl: avoid unaligned pointer reads/writes, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 11/14] hw/vfio/ccw: avoid taking address members in packed structs, Daniel P . Berrangé, 2019/03/29
- [qemu-s390x] [PATCH 13/14] hw/s390x/ipl: avoid taking address of fields in packed struct, Daniel P . Berrangé, 2019/03/29