aboutsummaryrefslogtreecommitdiffstats
path: root/cursor
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-09-12 23:07:45 +0200
committerSimon Ser <contact@emersion.fr>2025-06-08 16:16:09 +0000
commit0de833da296e59e2495738afc450d1d3cb0314b3 (patch)
tree997214f642a8a53dd3ccca0ad003c94498560c3b /cursor
parentcursor: Ignore invalid cursor files (diff)
downloadwayland-0de833da296e59e2495738afc450d1d3cb0314b3.tar
wayland-0de833da296e59e2495738afc450d1d3cb0314b3.tar.gz
wayland-0de833da296e59e2495738afc450d1d3cb0314b3.tar.bz2
wayland-0de833da296e59e2495738afc450d1d3cb0314b3.tar.lz
wayland-0de833da296e59e2495738afc450d1d3cb0314b3.tar.xz
wayland-0de833da296e59e2495738afc450d1d3cb0314b3.tar.zst
wayland-0de833da296e59e2495738afc450d1d3cb0314b3.zip
cursor: Properly check realloc for errors
Do not override realloc's input pointer before checking for errors, otherwise it's not possible to keep old value, as intended. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'cursor')
-rw-r--r--cursor/wayland-cursor.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c
index f3fef15..89ecc9a 100644
--- a/cursor/wayland-cursor.c
+++ b/cursor/wayland-cursor.c
@@ -351,6 +351,8 @@ load_callback(struct xcursor_images *images, void *data)
{
struct wl_cursor_theme *theme = data;
struct wl_cursor *cursor;
+ struct wl_cursor **p;
+ size_t s;
if (wl_cursor_theme_get_cursor(theme, images->name)) {
xcursor_images_destroy(images);
@@ -360,15 +362,14 @@ load_callback(struct xcursor_images *images, void *data)
cursor = wl_cursor_create_from_xcursor_images(images, theme);
if (cursor) {
- theme->cursor_count++;
- theme->cursors =
- realloc(theme->cursors,
- theme->cursor_count * sizeof theme->cursors[0]);
+ s = theme->cursor_count + 1;
+ p = realloc(theme->cursors, s * sizeof theme->cursors[0]);
- if (theme->cursors == NULL) {
- theme->cursor_count--;
+ if (p == NULL) {
free(cursor);
} else {
+ theme->cursor_count = s;
+ theme->cursors = p;
theme->cursors[theme->cursor_count - 1] = cursor;
}
}