diff options
| author | Simon Ser <contact@emersion.fr> | 2023-08-02 16:46:11 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2023-08-02 16:47:07 +0200 |
| commit | 7b27881cd1cbe55ec66c1455867eda9606eab8c7 (patch) | |
| tree | ca934de03606c1c6dde67f21583df94352aa266a /cursor/xcursor.c | |
| parent | protocol: fix whitespace (diff) | |
| download | wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.tar wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.tar.gz wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.tar.bz2 wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.tar.lz wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.tar.xz wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.tar.zst wayland-7b27881cd1cbe55ec66c1455867eda9606eab8c7.zip | |
cursor: check return value of snprintf()
Fixes a new warning in GCC 7:
FAILED: cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o
cc -Icursor/libwayland-cursor.so.0.22.90.p -Icursor -I../cursor -I. -I.. -Isrc -I../src -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c99 -O3 -D_POSIX_C_SOURCE=200809L -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -fPIC '-DICONDIR="/usr/share/X11/icons"' -MD -MQ cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o -MF cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o.d -o cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o -c ../cursor/xcursor.c
../cursor/xcursor.c: In function 'xcursor_load_theme':
../cursor/xcursor.c:596:39: error: '%s' directive output between 7 and 7 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
596 | snprintf(full, full_size, "%s/%s/%s", dir, subdir, file);
| ^~
......
764 | full = xcursor_build_fullname(dir, "cursors", "");
| ~~~~~~~~~
../cursor/xcursor.c:596:41: error: '/' directive output between 1 and 1 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
596 | snprintf(full, full_size, "%s/%s/%s", dir, subdir, file);
| ^
cc1: all warnings being treated as errors
Signed-off-by: Simon Ser <contact@emersion.fr>
Diffstat (limited to 'cursor/xcursor.c')
| -rw-r--r-- | cursor/xcursor.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/cursor/xcursor.c b/cursor/xcursor.c index 43a5292..6766c56 100644 --- a/cursor/xcursor.c +++ b/cursor/xcursor.c @@ -585,6 +585,7 @@ xcursor_build_fullname(const char *dir, const char *subdir, const char *file) { char *full; size_t full_size; + int ret; if (!dir || !subdir || !file) return NULL; @@ -593,7 +594,11 @@ xcursor_build_fullname(const char *dir, const char *subdir, const char *file) full = malloc(full_size); if (!full) return NULL; - snprintf(full, full_size, "%s/%s/%s", dir, subdir, file); + ret = snprintf(full, full_size, "%s/%s/%s", dir, subdir, file); + if (ret < 0) { + free(full); + return NULL; + } return full; } |
