diff options
author | William McKinnon <[email protected]> | 2022-04-27 17:33:23 -0400 |
---|---|---|
committer | William McKinnon <[email protected]> | 2022-04-27 17:33:23 -0400 |
commit | 7460d9f565092836f81b917a040caff57142d91a (patch) | |
tree | b76e7facef2aaa5925a62ad6b9995c16663313f0 /swaynag/swaynag.c | |
parent | c37aba2736e31264bdcd52147a96fa85e17c8c5f (diff) |
merge sway master
Diffstat (limited to 'swaynag/swaynag.c')
-rw-r--r-- | swaynag/swaynag.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 9b57d578..5620155d 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c @@ -28,8 +28,13 @@ static bool terminal_execute(char *terminal, char *command) { fprintf(tmp, "#!/bin/sh\nrm %s\n%s", fname, command); fclose(tmp); chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR); - char *cmd = malloc(sizeof(char) * (strlen(terminal) + strlen(" -e ") + strlen(fname) + 1)); - sprintf(cmd, "%s -e %s", terminal, fname); + size_t cmd_size = strlen(terminal) + strlen(" -e ") + strlen(fname) + 1; + char *cmd = malloc(cmd_size); + if (!cmd) { + perror("malloc"); + return false; + } + snprintf(cmd, cmd_size, "%s -e %s", terminal, fname); execlp("sh", "sh", "-c", cmd, NULL); sway_log_errno(SWAY_ERROR, "Failed to run command, execlp() returned."); free(cmd); @@ -58,7 +63,7 @@ static void swaynag_button_execute(struct swaynag *swaynag, } else if (pid == 0) { // Child of the child. Will be reparented to the init process char *terminal = getenv("TERMINAL"); - if (button->terminal && terminal && strlen(terminal)) { + if (button->terminal && terminal && *terminal) { sway_log(SWAY_DEBUG, "Found $TERMINAL: %s", terminal); if (!terminal_execute(terminal, button->action)) { swaynag_destroy(swaynag); @@ -138,7 +143,7 @@ static void update_cursor(struct swaynag_seat *seat) { const char *cursor_theme = getenv("XCURSOR_THEME"); unsigned cursor_size = 24; const char *env_cursor_size = getenv("XCURSOR_SIZE"); - if (env_cursor_size && strlen(env_cursor_size) > 0) { + if (env_cursor_size && *env_cursor_size) { errno = 0; char *end; unsigned size = strtoul(env_cursor_size, &end, 10); @@ -339,6 +344,7 @@ static void handle_global(void *data, struct wl_registry *registry, struct swaynag_seat *seat = calloc(1, sizeof(struct swaynag_seat)); if (!seat) { + perror("calloc"); return; } @@ -356,6 +362,10 @@ static void handle_global(void *data, struct wl_registry *registry, if (!swaynag->output) { struct swaynag_output *output = calloc(1, sizeof(struct swaynag_output)); + if (!output) { + perror("calloc"); + return; + } output->wl_output = wl_registry_bind(registry, name, &wl_output_interface, 4); output->wl_name = name; @@ -511,13 +521,8 @@ void swaynag_destroy(struct swaynag *swaynag) { swaynag_seat_destroy(seat); } - if (&swaynag->buffers[0]) { - destroy_buffer(&swaynag->buffers[0]); - } - - if (&swaynag->buffers[1]) { - destroy_buffer(&swaynag->buffers[1]); - } + destroy_buffer(&swaynag->buffers[0]); + destroy_buffer(&swaynag->buffers[1]); if (swaynag->outputs.prev || swaynag->outputs.next) { struct swaynag_output *output, *temp; |