diff options
| author | Simon Ser <contact@emersion.fr> | 2026-01-30 09:57:36 +0100 |
|---|---|---|
| committer | Pekka Paalanen <pq@iki.fi> | 2026-03-03 11:31:53 +0200 |
| commit | fe3a02c18a897c7cd89d50c1300305ffb7f55d86 (patch) | |
| tree | 7eb93658cfbf4bcc92ca4d547a1226f725c2787d | |
| parent | protocol: elaborate on drm_fourcc.h and wl_shm.format codes (diff) | |
| download | wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.tar wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.tar.gz wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.tar.bz2 wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.tar.lz wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.tar.xz wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.tar.zst wayland-fe3a02c18a897c7cd89d50c1300305ffb7f55d86.zip | |
util: assert alloc is consistent with data in wl_array_add()
struct wl_array may be constructed by users manually from a
foreign data pointer:
uint32_t states[] = {1, 2, 3};
struct wl_array arr = {
.data = states,
.size = sizeof(states) / sizeof(states[0]),
};
This is useful to avoid the need to allocate when sending Wayland
messages.
Users need to be careful not to use wl_array_add() on such arrays:
the function will misbehave by leaving garbage at the start of the
new buffer when reallocating.
Add an assert to guard against wl_array_add() calls in this
situation, to have a clear crash instead of undefined behavior.
Signed-off-by: Simon Ser <contact@emersion.fr>
| -rw-r--r-- | src/wayland-util.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/wayland-util.c b/src/wayland-util.c index 7231346..f551867 100644 --- a/src/wayland-util.c +++ b/src/wayland-util.c @@ -121,6 +121,9 @@ wl_array_add(struct wl_array *array, size_t size) alloc *= 2; if (array->alloc < alloc) { + if (array->alloc == 0 && array->data != NULL) + wl_abort("data is non-NULL with zero alloc"); + if (array->alloc > 0) data = realloc(array->data, alloc); else |
