wayland/tests/data
David Benjamin 8a7ecd774c util: fix undefined behavior in wl_array_for_each
If a wl_array has size zero, wl_array_for_each computes NULL + 0 to get
to the end pointer. This should be fine, and indeed it would be fine in
C++. But the C specification has a mistake here and it is actually
undefined behavior. See
https://davidben.net/2024/01/15/empty-slices.html

Clang's -fsanitize=undefined flags this. I ran into this in Chromium's
build with wayland-scanner on one of our XML files.

../../third_party/wayland/src/src/scanner.c:1853:2: runtime error: applying zero offset to null pointer
    #0 0x55c979b8e02c in emit_code third_party/wayland/src/src/scanner.c:1853:2
    #1 0x55c979b89323 in main third_party/wayland/src/src/scanner.c
    #2 0x7f8dfdb8c6c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #3 0x7f8dfdb8c784 in __libc_start_main csu/../csu/libc-start.c:360:3
    #4 0x55c979b70f39 in _start (...)

An empty XML file is sufficient to hit this case, so I've added it as a
test. To reproduce, undo the fix and include only the test, then build
with:

  CC=clang CFLAGS="-fno-sanitize-recover=undefined" meson build/ -Db_sanitize=undefined -Db_lundef=false
  ninja -C build test

Signed-off-by: David Benjamin <davidben@google.com>
2024-03-24 20:00:01 -04:00
..
bad-identifier-arg.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
bad-identifier-entry.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
bad-identifier-enum.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
bad-identifier-event.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
bad-identifier-interface.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
bad-identifier-protocol.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
bad-identifier-request.xml tests: Verify that wayland_scanner can catch bad identifiers 2019-05-02 17:42:59 +00:00
empty-client.h util: fix undefined behavior in wl_array_for_each 2024-03-24 20:00:01 -04:00
empty-code.c util: fix undefined behavior in wl_array_for_each 2024-03-24 20:00:01 -04:00
empty-server.h util: fix undefined behavior in wl_array_for_each 2024-03-24 20:00:01 -04:00
empty.xml util: fix undefined behavior in wl_array_for_each 2024-03-24 20:00:01 -04:00
example-client.h doc: fix typo in wl_data_device.data_offer 2022-01-10 10:07:22 +00:00
example-code.c scanner: prepend protocol name to types symbol 2019-09-11 13:27:03 -05:00
example-server.h tests: Test wayland-scanner with a description in an entry 2021-07-07 12:11:42 +00:00
example.xml doc: fix typo in wl_data_device.data_offer 2022-01-10 10:07:22 +00:00
README.md build: add a gen-scanner-test target 2024-01-15 14:29:10 +01:00
small-client-core.h scanner: Use the new atomic marshal/destroy function 2021-08-07 11:53:23 +00:00
small-client.h scanner: Use the new atomic marshal/destroy function 2021-08-07 11:53:23 +00:00
small-code-core.c scanner: prepend protocol name to types symbol 2019-09-11 13:27:03 -05:00
small-code.c scanner: prepend protocol name to types symbol 2019-09-11 13:27:03 -05:00
small-private-code.c scanner: prepend protocol name to types symbol 2019-09-11 13:27:03 -05:00
small-server-core.h scanner: Guard interface declarations 2020-04-23 10:17:18 +02:00
small-server.h scanner: Guard interface declarations 2020-04-23 10:17:18 +02:00
small.xml Replace initial 8 spaces with a tab for all xml files 2020-04-29 12:21:33 +00:00

To re-generate the test data, run:

ninja -C build/ gen-scanner-test