aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag/config.c
diff options
context:
space:
mode:
authorLibravatar Nihal Jere <nihal@nihaljere.xyz>2022-02-25 11:40:04 -0600
committerLibravatar Simon Zeni <simon@bl4ckb0ne.ca>2022-02-28 11:24:13 -0500
commit061ffc30ea899c3ed77004065d3958f19e3bb884 (patch)
tree5e1874ef52852964732b2552671d0171623b1543 /swaynag/config.c
parentDon't enter seatop_move_floating when fullscreen (diff)
downloadsway-061ffc30ea899c3ed77004065d3958f19e3bb884.tar.gz
sway-061ffc30ea899c3ed77004065d3958f19e3bb884.tar.zst
sway-061ffc30ea899c3ed77004065d3958f19e3bb884.zip
swaynag: die on all allocation failures
Diffstat (limited to 'swaynag/config.c')
-rw-r--r--swaynag/config.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index ede0938c..73fc41c8 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -19,6 +19,10 @@ static char *read_from_stdin(void) {
19 ssize_t nread; 19 ssize_t nread;
20 while ((nread = getline(&line, &line_size, stdin)) != -1) { 20 while ((nread = getline(&line, &line_size, stdin)) != -1) {
21 buffer = realloc(buffer, buffer_len + nread + 1); 21 buffer = realloc(buffer, buffer_len + nread + 1);
22 if (!buffer) {
23 perror("realloc");
24 return NULL;
25 }
22 snprintf(&buffer[buffer_len], nread + 1, "%s", line); 26 snprintf(&buffer[buffer_len], nread + 1, "%s", line);
23 buffer_len += nread; 27 buffer_len += nread;
24 } 28 }
@@ -152,6 +156,10 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
152 } 156 }
153 struct swaynag_button *button; 157 struct swaynag_button *button;
154 button = calloc(sizeof(struct swaynag_button), 1); 158 button = calloc(sizeof(struct swaynag_button), 1);
159 if (!button) {
160 perror("calloc");
161 return EXIT_FAILURE;
162 }
155 button->text = strdup(optarg); 163 button->text = strdup(optarg);
156 button->type = SWAYNAG_ACTION_COMMAND; 164 button->type = SWAYNAG_ACTION_COMMAND;
157 button->action = strdup(argv[optind]); 165 button->action = strdup(argv[optind]);
@@ -215,6 +223,9 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
215 if (swaynag) { 223 if (swaynag) {
216 free(swaynag->details.message); 224 free(swaynag->details.message);
217 swaynag->details.message = read_from_stdin(); 225 swaynag->details.message = read_from_stdin();
226 if (!swaynag->details.message) {
227 return EXIT_FAILURE;
228 }
218 swaynag->details.button_up.text = strdup("▲"); 229 swaynag->details.button_up.text = strdup("▲");
219 swaynag->details.button_down.text = strdup("▼"); 230 swaynag->details.button_down.text = strdup("▼");
220 } 231 }
@@ -406,6 +417,10 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
406 break; 417 break;
407 } 418 }
408 char *name = calloc(1, close - line); 419 char *name = calloc(1, close - line);
420 if (!name) {
421 perror("calloc");
422 return EXIT_FAILURE;
423 }
409 strncat(name, line + 1, close - line - 1); 424 strncat(name, line + 1, close - line - 1);
410 type = swaynag_type_get(types, name); 425 type = swaynag_type_get(types, name);
411 if (!type) { 426 if (!type) {
@@ -415,6 +430,10 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
415 free(name); 430 free(name);
416 } else { 431 } else {
417 char *flag = malloc(nread + 3); 432 char *flag = malloc(nread + 3);
433 if (!flag) {
434 perror("calloc");
435 return EXIT_FAILURE;
436 }
418 snprintf(flag, nread + 3, "--%s", line); 437 snprintf(flag, nread + 3, "--%s", line);
419 char *argv[] = {"swaynag", flag}; 438 char *argv[] = {"swaynag", flag};
420 result = swaynag_parse_options(2, argv, swaynag, types, type, 439 result = swaynag_parse_options(2, argv, swaynag, types, type,