diff options
Diffstat (limited to 'sway/commands/set.c')
-rw-r--r-- | sway/commands/set.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sway/commands/set.c b/sway/commands/set.c index 8b293825..1d6bce04 100644 --- a/sway/commands/set.c +++ b/sway/commands/set.c | |||
@@ -1,5 +1,7 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
1 | #include <stdio.h> | 2 | #include <stdio.h> |
2 | #include <string.h> | 3 | #include <string.h> |
4 | #include <strings.h> | ||
3 | #include "sway/commands.h" | 5 | #include "sway/commands.h" |
4 | #include "sway/config.h" | 6 | #include "sway/config.h" |
5 | #include "list.h" | 7 | #include "list.h" |
@@ -14,7 +16,6 @@ static int compare_set_qsort(const void *_l, const void *_r) { | |||
14 | 16 | ||
15 | struct cmd_results *cmd_set(int argc, char **argv) { | 17 | struct cmd_results *cmd_set(int argc, char **argv) { |
16 | char *tmp; | 18 | char *tmp; |
17 | int size; | ||
18 | struct cmd_results *error = NULL; | 19 | struct cmd_results *error = NULL; |
19 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file."); | 20 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file."); |
20 | if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { | 21 | if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { |
@@ -24,13 +25,14 @@ struct cmd_results *cmd_set(int argc, char **argv) { | |||
24 | if (argv[0][0] != '$') { | 25 | if (argv[0][0] != '$') { |
25 | sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); | 26 | sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); |
26 | 27 | ||
27 | size = asprintf(&tmp, "%s%s", "$", argv[0]); | 28 | size_t size = snprintf(NULL, 0, "$%s", argv[0]); |
28 | if (size == -1) { | 29 | tmp = malloc(size + 1); |
30 | if (!tmp) { | ||
29 | return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]); | 31 | return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]); |
30 | } | 32 | } |
33 | snprintf(tmp, size, "$%s", argv[0]); | ||
31 | 34 | ||
32 | argv[0] = strdup(tmp); | 35 | argv[0] = tmp; |
33 | free(tmp); | ||
34 | } | 36 | } |
35 | 37 | ||
36 | struct sway_variable *var = NULL; | 38 | struct sway_variable *var = NULL; |