drivers/usb.c: rework descriptor read logic in get_descriptor()
When compiling with gcc 12 drivers/usb.c generates the following error:
/root/drivers/usb.c: In function 'get_descriptor':
/root/drivers/usb.c:200:23: error: array subscript 'device_descriptor_t[0]' is partly outside array bounds of 'u8[8]' {aka 'unsigned char[8]'} [-Werror=array-bounds]
200 | if (dd->bMaxPacketSize0 != 0)
| ^~
/root/drivers/usb.c:181:12: note: object 'buf' of size 8
181 | u8 buf[8];
| ^~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:229: target/drivers/usb.o] Error 1
make[1]: Leaving directory '/root/obj-ppc'
The compiler is complaining that a device_descriptor_t pointer cast to the 8 byte buffer
means that a pointer dereference to some members of the device_descriptor_t could go
beyond the end of the 8 byte buffer. Whilst this sounds as if it should be allowed, some
searching suggests that the behaviour of such a cast is undefined.
Rework get_descriptor() so that an entire device_descriptor_t is used to store the first
8 bytes of the incoming descriptor, and update the buf references to use the equivalent
device_descriptor_t fields instead.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
1 file changed