Bug#997082: qemu: FTBFS: 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]

2021-10-23 Thread Michael Tokarev

23.10.2021 19:33, Lucas Nussbaum wrote:

Source: qemu
Version: 1:6.1+dfsg-6
Severity: serious
Justification: FTBFS
Tags: bookworm sid ftbfs
User: lu...@debian.org
Usertags: ftbfs-20211023 ftbfs-bullseye

Hi,

During a rebuild of all packages in sid, your package failed to build
on amd64.


Relevant part (hopefully):

powerpc64-linux-gnu-gcc $EXTRACFLAGS -m32 -mcpu=604 -msoft-float -fno-builtin-bcopy -fno-builtin-log2 -Os -g 
-DNATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH -USWAP_ENDIANNESS -Wall -Wredundant-decls -Wshadow -Wpointer-arith 
-Wstrict-prototypes -Wmissing-declarations -Wundef -Wendif-labels -Wstrict-aliasing -Wwrite-strings 
-Wmissing-prototypes -Wnested-externs -Werror -MMD -MP -MT target/drivers/usbohci_rh.o -MF 
'target/drivers/usbohci_rh.d' -I/<>/roms/openbios/include 
-I/<>/roms/openbios/kernel/include -I./target/include -c -o target/drivers/usbohci_rh.o 
/<>/roms/openbios/drivers/usbohci_rh.c
/<>/roms/openbios/drivers/usb.c: In function ‘get_descriptor’:
/<>/roms/openbios/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)
   |   ^~
/<>/roms/openbios/drivers/usb.c:181:12: note: while referencing 
‘buf’
   181 | u8 buf[8];
   |^~~


This is interesting. And I'm not really sure what to do with this.
The code is right, and gcc is too picky there. The thing is,
while the buffer is indeed smaller than the size of the structure
to which it is casted there, but the actual code does not access
past the buffer, bMaxPacketSize0 is byte #7 (counting from 0) there
which is exactly the last byte of buf[] array.

I haven't seen this warning before, it must be some new gcc
addition, and gcc is being too smart there :)

I agree the code is cloudy there, it can have been written
more clearly. So I can't say this is really a bug in gcc,
it is like classic "variable can be used uninitialized" while
it actually is not, for example because all relevant switch(){}
statements leads to return but gcc can not figure it out.

Thanks,

/mjt



Bug#997082: qemu: FTBFS: 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]

2021-10-23 Thread Lucas Nussbaum
Source: qemu
Version: 1:6.1+dfsg-6
Severity: serious
Justification: FTBFS
Tags: bookworm sid ftbfs
User: lu...@debian.org
Usertags: ftbfs-20211023 ftbfs-bullseye

Hi,

During a rebuild of all packages in sid, your package failed to build
on amd64.


Relevant part (hopefully):
> powerpc64-linux-gnu-gcc $EXTRACFLAGS -m32 -mcpu=604 -msoft-float 
> -fno-builtin-bcopy -fno-builtin-log2 -Os -g 
> -DNATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH -USWAP_ENDIANNESS -Wall 
> -Wredundant-decls -Wshadow -Wpointer-arith -Wstrict-prototypes 
> -Wmissing-declarations -Wundef -Wendif-labels -Wstrict-aliasing 
> -Wwrite-strings -Wmissing-prototypes -Wnested-externs -Werror -MMD -MP -MT 
> target/drivers/usbohci_rh.o -MF 'target/drivers/usbohci_rh.d' 
> -I/<>/roms/openbios/include 
> -I/<>/roms/openbios/kernel/include -I./target/include -c -o 
> target/drivers/usbohci_rh.o 
> /<>/roms/openbios/drivers/usbohci_rh.c
> /<>/roms/openbios/drivers/usb.c: In function ‘get_descriptor’:
> /<>/roms/openbios/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)
>   |   ^~
> /<>/roms/openbios/drivers/usb.c:181:12: note: while referencing 
> ‘buf’
>   181 | u8 buf[8];
>   |^~~
> /<>/roms/openbios/drivers/usbohci.c: In function 
> ‘ohci_create_intr_queue’:
> /<>/roms/openbios/drivers/usbohci.c:703:35: warning: taking 
> address of packed member of ‘struct ’ may result in an unaligned 
> pointer value [-Waddress-of-packed-member]
>   703 | u32 *const intr_table   = ohci->hcca->HccaInterruptTable;
>   |   ^~~~
> /<>/roms/openbios/drivers/usbohci.c: In function 
> ‘ohci_destroy_intr_queue’:
> /<>/roms/openbios/drivers/usbohci.c:734:35: warning: taking 
> address of packed member of ‘struct ’ may result in an unaligned 
> pointer value [-Waddress-of-packed-member]
>   734 | u32 *const intr_table   = ohci->hcca->HccaInterruptTable;
>   |   ^~~~
> /<>/roms/openbios/drivers/usbohci.c: In function 
> ‘ohci_process_done_queue’:
> /<>/roms/openbios/drivers/usbohci.c:840:25: warning: converting 
> a packed ‘td_t’ pointer (alignment 1) to a ‘intrq_td_t’ {aka ‘struct 
> _intrq_td’} pointer (alignment 4) may result in an unaligned pointer value 
> [-Waddress-of-packed-member]
>   840 | intrq_td_t *const td = 
> INTRQ_TD_FROM_TD(done_td);
>   | ^~
> /<>/roms/openbios/drivers/usbohci.c:607:8: note: defined here
>   607 | struct _intrq_td {
>   |^
> cc1: all warnings being treated as errors
> make[1]: *** [rules.mak:229: target/drivers/usb.o] Error 1


The full build log is available from:
http://qa-logs.debian.net/2021/10/23/qemu_6.1+dfsg-6_unstable.log

A list of current common problems and possible solutions is available at
http://wiki.debian.org/qa.debian.org/FTBFS . You're welcome to contribute!

If you reassign this bug to another package, please marking it as 'affects'-ing
this package. See https://www.debian.org/Bugs/server-control#affects

If you fail to reproduce this, please provide a build log and diff it with mine
so that we can identify if something relevant changed in the meantime.