aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output/background.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/output/background.c')
-rw-r--r--sway/commands/output/background.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c
index 68ee9fe1..d691295f 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) {
102 } 102 }
103 103
104 char *conf_path = dirname(conf); 104 char *conf_path = dirname(conf);
105 char *rel_path = src; 105 char *real_src = malloc(strlen(conf_path) + strlen(src) + 2);
106 src = malloc(strlen(conf_path) + strlen(src) + 2); 106 if (!real_src) {
107 if (!src) { 107 free(src);
108 free(rel_path);
109 free(conf); 108 free(conf);
110 sway_log(SWAY_ERROR, "Unable to allocate memory"); 109 sway_log(SWAY_ERROR, "Unable to allocate memory");
111 return cmd_results_new(CMD_FAILURE, 110 return cmd_results_new(CMD_FAILURE,
112 "Unable to allocate resources"); 111 "Unable to allocate resources");
113 } 112 }
114 113
115 sprintf(src, "%s/%s", conf_path, rel_path); 114 snprintf(real_src, strlen(conf_path) + strlen(src) + 2, "%s/%s", conf_path, src);
116 free(rel_path); 115 free(src);
117 free(conf); 116 free(conf);
117 src = real_src;
118 } 118 }
119 119
120 bool can_access = access(src, F_OK) != -1; 120 bool can_access = access(src, F_OK) != -1;
@@ -123,7 +123,10 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
123 src); 123 src);
124 config_add_swaynag_warning("Unable to access background file '%s'", 124 config_add_swaynag_warning("Unable to access background file '%s'",
125 src); 125 src);
126 struct cmd_results *result = cmd_results_new(CMD_FAILURE,
127 "unable to access background file '%s'", src);
126 free(src); 128 free(src);
129 return result;
127 } else { 130 } else {
128 output->background = src; 131 output->background = src;
129 output->background_option = strdup(mode); 132 output->background_option = strdup(mode);