aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag
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
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')
-rw-r--r--swaynag/config.c19
-rw-r--r--swaynag/main.c8
-rw-r--r--swaynag/swaynag.c9
3 files changed, 36 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,
diff --git a/swaynag/main.c b/swaynag/main.c
index 88007818..0c94cb1a 100644
--- a/swaynag/main.c
+++ b/swaynag/main.c
@@ -32,12 +32,20 @@ int main(int argc, char **argv) {
32 32
33 struct swaynag_button *button_close = 33 struct swaynag_button *button_close =
34 calloc(sizeof(struct swaynag_button), 1); 34 calloc(sizeof(struct swaynag_button), 1);
35 if (!button_close) {
36 perror("calloc");
37 return EXIT_FAILURE;
38 }
35 button_close->text = strdup("X"); 39 button_close->text = strdup("X");
36 button_close->type = SWAYNAG_ACTION_DISMISS; 40 button_close->type = SWAYNAG_ACTION_DISMISS;
37 list_add(swaynag.buttons, button_close); 41 list_add(swaynag.buttons, button_close);
38 42
39 swaynag.details.button_details = 43 swaynag.details.button_details =
40 calloc(sizeof(struct swaynag_button), 1); 44 calloc(sizeof(struct swaynag_button), 1);
45 if (!swaynag.details.button_details) {
46 perror("calloc");
47 return EXIT_FAILURE;
48 }
41 swaynag.details.button_details->text = strdup("Toggle details"); 49 swaynag.details.button_details->text = strdup("Toggle details");
42 swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND; 50 swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND;
43 51
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c
index 23d23f38..60ae3e8f 100644
--- a/swaynag/swaynag.c
+++ b/swaynag/swaynag.c
@@ -30,6 +30,10 @@ static bool terminal_execute(char *terminal, char *command) {
30 chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR); 30 chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR);
31 size_t cmd_size = strlen(terminal) + strlen(" -e ") + strlen(fname) + 1; 31 size_t cmd_size = strlen(terminal) + strlen(" -e ") + strlen(fname) + 1;
32 char *cmd = malloc(cmd_size); 32 char *cmd = malloc(cmd_size);
33 if (!cmd) {
34 perror("malloc");
35 return false;
36 }
33 snprintf(cmd, cmd_size, "%s -e %s", terminal, fname); 37 snprintf(cmd, cmd_size, "%s -e %s", terminal, fname);
34 execlp("sh", "sh", "-c", cmd, NULL); 38 execlp("sh", "sh", "-c", cmd, NULL);
35 sway_log_errno(SWAY_ERROR, "Failed to run command, execlp() returned."); 39 sway_log_errno(SWAY_ERROR, "Failed to run command, execlp() returned.");
@@ -340,6 +344,7 @@ static void handle_global(void *data, struct wl_registry *registry,
340 struct swaynag_seat *seat = 344 struct swaynag_seat *seat =
341 calloc(1, sizeof(struct swaynag_seat)); 345 calloc(1, sizeof(struct swaynag_seat));
342 if (!seat) { 346 if (!seat) {
347 perror("calloc");
343 return; 348 return;
344 } 349 }
345 350
@@ -357,6 +362,10 @@ static void handle_global(void *data, struct wl_registry *registry,
357 if (!swaynag->output) { 362 if (!swaynag->output) {
358 struct swaynag_output *output = 363 struct swaynag_output *output =
359 calloc(1, sizeof(struct swaynag_output)); 364 calloc(1, sizeof(struct swaynag_output));
365 if (!output) {
366 perror("calloc");
367 return;
368 }
360 output->wl_output = wl_registry_bind(registry, name, 369 output->wl_output = wl_registry_bind(registry, name,
361 &wl_output_interface, 4); 370 &wl_output_interface, 4);
362 output->wl_name = name; 371 output->wl_name = name;