From 68f63e5d6f62e80bb758b54c59e9be387cd84491 Mon Sep 17 00:00:00 2001 From: Guillaume Chereau Date: Tue, 26 Mar 2024 12:45:48 +0800 Subject: [PATCH] Fix compilation warnings on linux gcc doesn't like when we use snprintf to concatenate buffers that can maybe truncate the result. Fix that by lowering the max path size for directories only. Not very clean but I am not sure how to fix that in a better way. --- src/system.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/system.c b/src/system.c index 7c3f5528f..683ffdac8 100644 --- a/src/system.c +++ b/src/system.c @@ -30,6 +30,8 @@ #define PATH_MAX 1024 #endif +#define PATH_MAX_DIR (PATH_MAX - 128) + #define USER_PASS(...) ((const void*[]){__VA_ARGS__}) #define USER_GET(var, n) (((void**)var)[n]) @@ -44,7 +46,7 @@ sys_callbacks_t sys_callbacks = {}; static const char *get_user_dir(void) { - static char ret[PATH_MAX] = ""; + static char ret[PATH_MAX_DIR] = ""; const char *home; if (!*ret) { home = getenv("XDG_CONFIG_HOME"); @@ -338,7 +340,7 @@ static bool path_exists(const char *path) int sys_iter_paths(int location, int options, const char *name, void *arg, int (*f)(void *arg, const char *path)) { - char base_dir[PATH_MAX]; + char base_dir[PATH_MAX_DIR]; char path[PATH_MAX]; int r;