Skip to content

Commit

Permalink
Fix compilation warnings on linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guillaumechereau committed Mar 26, 2024
1 parent 2f4e4f9 commit 68f63e5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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");
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 68f63e5

Please sign in to comment.