Build failure on upcoming gcc-12: render/picture.c:874:26: error: array subscript 'union _SourcePict[0]' is partly outside array bounds
gcc-12
became slightly stricter at detecting writes into casted struct: https://gcc.gnu.org/PR103292
Now xserver
fails the build due to -Werror=array-bounds
:
xserver/b $ ninja -k0
[1/14] Compiling C object render/liblibxserver_render.a.p/picture.c.o
FAILED: render/liblibxserver_render.a.p/picture.c.o
gcc -Irender/liblibxserver_render.a.p -Irender -I../render -IXext -I../Xext -IXi -I../Xi -Icomposite -I../composite -Idamageext -I../damageext -Iexa -I../exa -Ifb -I../fb -Iglamor -I../glamor -Imi -I../mi -Imiext/damage -I../miext/damage -Imiext/shadow -I../miext/shadow -Imiext/sync -I../miext/sync -Idbe -I../dbe -Idri3 -I../dri3 -Iinclude -I../include -Ipresent -I../present -Irandr -I../randr -Ixfixes -I../xfixes -I/nix/store/n4lkr36d9fdbk4mkz211lkb4bbr8rzds-xorgproto-2021.5/include -I/nix/store/k3gglsxrd6z4ibr6254lnnxfjlcfc1mb-xtrans-1.4.0/include -I/nix/store/va18z5jayx7cx1yclw7ka38vk9zz1byc-systemd-249.5-dev/include -I/nix/store/n4lkr36d9fdbk4mkz211lkb4bbr8rzds-xorgproto-2021.5/include/X11/dri -I/nix/store/wpx7mnj7d674v43jmmhsd23lwjy8cjg8-pixman-0.38.4/include/pixman-1 -I/nix/store/d0bvjgalgf4psyc27iiddp1rqmb0l86v-libxkbfile-1.1.0-dev/include -I/nix/store/j2gprxdanxjn8195b0ms739dq6iv9qv9-libXfont2-2.0.5/include -I/nix/store/38vca6fmb6lrnikcypz5k4avk0c90bpa-libXdmcp-1.1.3-dev/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=gnu99 -O2 -g -DHAVE_DIX_CONFIG_H -fno-strict-aliasing -fvisibility=hidden -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wunused -Wuninitialized -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -fPIC -D_DEFAULT_SOURCE -D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT -MD -MQ render/liblibxserver_render.a.p/picture.c.o -MF render/liblibxserver_render.a.p/picture.c.o.d -o render/liblibxserver_render.a.p/picture.c.o -c ../render/picture.c
../render/picture.c: In function 'CreateSolidPicture':
../render/picture.c:874:26: error: array subscript 'union _SourcePict[0]' is partly outside array bounds of 'unsigned char[16]' [-Werror=array-bounds]
874 | pPicture->pSourcePict->type = SourcePictTypeSolidFill;
| ^~
../render/picture.c:868:45: note: object of size 16 allocated by 'malloc'
868 | pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictSolidFill));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../render/picture.c: In function 'CreateLinearGradientPicture':
../render/picture.c:906:26: error: array subscript 'union _SourcePict[0]' is partly outside array bounds of 'unsigned char[32]' [-Werror=array-bounds]
906 | pPicture->pSourcePict->linear.type = SourcePictTypeLinear;
| ^~
../render/picture.c:899:45: note: object of size 32 allocated by 'malloc'
899 | pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictLinearGradient));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../render/picture.c: In function 'CreateConicalGradientPicture':
../render/picture.c:989:26: error: array subscript 'union _SourcePict[0]' is partly outside array bounds of 'unsigned char[32]' [-Werror=array-bounds]
989 | pPicture->pSourcePict->conical.type = SourcePictTypeConical;
| ^~
../render/picture.c:982:45: note: object of size 32 allocated by 'malloc'
982 | pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictConicalGradient));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
ninja: build stopped: cannot make progress due to previous errors.
Compiler version is a fresh gcc
snapshot:
$ LANG=C gcc -v
Using built-in specs.
COLLECT_GCC=/nix/store/59jdmdy3ylrpmap1bjxic1fjaq8wf96s-gcc-12.0.0/bin/gcc
COLLECT_LTO_WRAPPER=/nix/store/59jdmdy3ylrpmap1bjxic1fjaq8wf96s-gcc-12.0.0/libexec/gcc/x86_64-unknown-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211114 (experimental) (GCC)
Happens on both most recent 1.20.13
release and on git checkout.