]> git.ipfire.org Git - thirdparty/systemd.git/commit - meson.build
meson: enable -Warray-bounds and -fstrict-flex-arrays
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 5 Feb 2023 19:44:19 +0000 (20:44 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 6 Feb 2023 11:09:55 +0000 (12:09 +0100)
commitfc5688375c76a1e367ddb1f5b51603f1f2b4d081
treef1d7f9f91bf0ff0a3027b3a363544f03696ffbd5
parentf41e4b82a42e22f7cdc9a05d02125bdc63334e6a
meson: enable -Warray-bounds and -fstrict-flex-arrays

-fstrict-flex-arrays means that the compiler doesn't have to assume that any
trailing array is a flex array. I.e. unless the array is declared without a
specified size, only indices in the declared range are valid.

-Warray-bounds turns on the warnings about out-of-bounds array accesses.
-Warray-bounds=2 does some more warnings, with higher false positive rate. But
it doesn't seem to yield any false positives in our codebase, so enable it.

clang supports -Warray-bounds, but not -Warray-bounds=2.
gcc supports both.
gcc-13 supports -fstrict-flex-arrays.

See https://people.kernel.org/kees/bounded-flexible-arrays-in-c for a long
discussion of use in the kernel.
meson.build