diff options
author | Daniel De Graaf <code@danieldg.net> | 2022-04-09 12:10:24 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-04-09 18:27:57 +0200 |
commit | cf413b9c0b688689a3d4e29d873a749889ecc971 (patch) | |
tree | 757cd526c20835caa4884143b3fd3937cb9115ea | |
parent | 20181974c221c84a3c857e83f4f51419ca1a8b23 (diff) |
Shuffle variables to satisfy -Werror=restrict
This also fixes an invalid strlen invocation on uninitialized memory.
-rw-r--r-- | sway/commands/output/background.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 1a3939d4..67f212ff 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -102,19 +102,19 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { } char *conf_path = dirname(conf); - char *rel_path = src; - src = malloc(strlen(conf_path) + strlen(src) + 2); - if (!src) { - free(rel_path); + char *real_src = malloc(strlen(conf_path) + strlen(src) + 2); + if (!real_src) { + free(src); free(conf); sway_log(SWAY_ERROR, "Unable to allocate memory"); return cmd_results_new(CMD_FAILURE, "Unable to allocate resources"); } - snprintf(src, strlen(conf_path) + strlen(src) + 2, "%s/%s", conf_path, rel_path); - free(rel_path); + snprintf(real_src, strlen(conf_path) + strlen(src) + 2, "%s/%s", conf_path, src); + free(src); free(conf); + src = real_src; } bool can_access = access(src, F_OK) != -1; |