diff options
-rw-r--r-- | common/pango.c | 20 | ||||
-rw-r--r-- | sway/commands.c | 12 | ||||
-rw-r--r-- | sway/commands/bar.c | 4 | ||||
-rw-r--r-- | sway/config.c | 15 | ||||
-rw-r--r-- | sway/config/output.c | 9 | ||||
-rw-r--r-- | sway/input/cursor.c | 15 | ||||
-rw-r--r-- | sway/input/input-manager.c | 10 | ||||
-rw-r--r-- | sway/input/keyboard.c | 29 | ||||
-rw-r--r-- | sway/swaynag.c | 14 | ||||
-rw-r--r-- | swaybar/tray/host.c | 10 | ||||
-rw-r--r-- | swaybar/tray/icon.c | 26 | ||||
-rw-r--r-- | swaybar/tray/watcher.c | 9 |
12 files changed, 39 insertions, 134 deletions
diff --git a/common/pango.c b/common/pango.c index e04bf80f..288569b3 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -84,18 +84,11 @@ void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width, | |||
84 | int *baseline, double scale, bool markup, const char *fmt, ...) { | 84 | int *baseline, double scale, bool markup, const char *fmt, ...) { |
85 | va_list args; | 85 | va_list args; |
86 | va_start(args, fmt); | 86 | va_start(args, fmt); |
87 | // Add one since vsnprintf excludes null terminator. | 87 | char *buf = vformat_str(fmt, args); |
88 | int length = vsnprintf(NULL, 0, fmt, args) + 1; | ||
89 | va_end(args); | 88 | va_end(args); |
90 | |||
91 | char *buf = malloc(length); | ||
92 | if (buf == NULL) { | 89 | if (buf == NULL) { |
93 | sway_log(SWAY_ERROR, "Failed to allocate memory"); | ||
94 | return; | 90 | return; |
95 | } | 91 | } |
96 | va_start(args, fmt); | ||
97 | vsnprintf(buf, length, fmt, args); | ||
98 | va_end(args); | ||
99 | 92 | ||
100 | PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup); | 93 | PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup); |
101 | pango_cairo_update_layout(cairo, layout); | 94 | pango_cairo_update_layout(cairo, layout); |
@@ -104,6 +97,7 @@ void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width, | |||
104 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; | 97 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; |
105 | } | 98 | } |
106 | g_object_unref(layout); | 99 | g_object_unref(layout); |
100 | |||
107 | free(buf); | 101 | free(buf); |
108 | } | 102 | } |
109 | 103 | ||
@@ -125,18 +119,11 @@ void render_text(cairo_t *cairo, const PangoFontDescription *desc, | |||
125 | double scale, bool markup, const char *fmt, ...) { | 119 | double scale, bool markup, const char *fmt, ...) { |
126 | va_list args; | 120 | va_list args; |
127 | va_start(args, fmt); | 121 | va_start(args, fmt); |
128 | // Add one since vsnprintf excludes null terminator. | 122 | char *buf = vformat_str(fmt, args); |
129 | int length = vsnprintf(NULL, 0, fmt, args) + 1; | ||
130 | va_end(args); | 123 | va_end(args); |
131 | |||
132 | char *buf = malloc(length); | ||
133 | if (buf == NULL) { | 124 | if (buf == NULL) { |
134 | sway_log(SWAY_ERROR, "Failed to allocate memory"); | ||
135 | return; | 125 | return; |
136 | } | 126 | } |
137 | va_start(args, fmt); | ||
138 | vsnprintf(buf, length, fmt, args); | ||
139 | va_end(args); | ||
140 | 127 | ||
141 | PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup); | 128 | PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup); |
142 | cairo_font_options_t *fo = cairo_font_options_create(); | 129 | cairo_font_options_t *fo = cairo_font_options_create(); |
@@ -146,5 +133,6 @@ void render_text(cairo_t *cairo, const PangoFontDescription *desc, | |||
146 | pango_cairo_update_layout(cairo, layout); | 133 | pango_cairo_update_layout(cairo, layout); |
147 | pango_cairo_show_layout(cairo, layout); | 134 | pango_cairo_show_layout(cairo, layout); |
148 | g_object_unref(layout); | 135 | g_object_unref(layout); |
136 | |||
149 | free(buf); | 137 | free(buf); |
150 | } | 138 | } |
diff --git a/sway/commands.c b/sway/commands.c index 0ea44129..55eda183 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -489,20 +489,10 @@ struct cmd_results *cmd_results_new(enum cmd_status status, | |||
489 | } | 489 | } |
490 | results->status = status; | 490 | results->status = status; |
491 | if (format) { | 491 | if (format) { |
492 | char *error = NULL; | ||
493 | va_list args; | 492 | va_list args; |
494 | va_start(args, format); | 493 | va_start(args, format); |
495 | int slen = vsnprintf(NULL, 0, format, args); | 494 | results->error = vformat_str(format, args); |
496 | va_end(args); | 495 | va_end(args); |
497 | if (slen > 0) { | ||
498 | error = malloc(slen + 1); | ||
499 | if (error != NULL) { | ||
500 | va_start(args, format); | ||
501 | vsnprintf(error, slen + 1, format, args); | ||
502 | va_end(args); | ||
503 | } | ||
504 | } | ||
505 | results->error = error; | ||
506 | } else { | 496 | } else { |
507 | results->error = NULL; | 497 | results->error = NULL; |
508 | } | 498 | } |
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 8571d282..22756acb 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -73,12 +73,10 @@ struct cmd_results *cmd_bar(int argc, char **argv) { | |||
73 | } | 73 | } |
74 | ++argv; --argc; | 74 | ++argv; --argc; |
75 | } else if (config->reading && !config->current_bar) { | 75 | } else if (config->reading && !config->current_bar) { |
76 | int len = snprintf(NULL, 0, "bar-%d", config->bars->length) + 1; | 76 | id = format_str("bar-%d", config->bars->length); |
77 | id = malloc(len * sizeof(char)); | ||
78 | if (!id) { | 77 | if (!id) { |
79 | return cmd_results_new(CMD_FAILURE, "Unable to allocate bar id"); | 78 | return cmd_results_new(CMD_FAILURE, "Unable to allocate bar id"); |
80 | } | 79 | } |
81 | snprintf(id, len, "bar-%d", config->bars->length); | ||
82 | } else if (!config->reading && strcmp(argv[0], "mode") != 0 && | 80 | } else if (!config->reading && strcmp(argv[0], "mode") != 0 && |
83 | strcmp(argv[0], "hidden_state") != 0) { | 81 | strcmp(argv[0], "hidden_state") != 0) { |
84 | if (is_subcommand(argv[0])) { | 82 | if (is_subcommand(argv[0])) { |
diff --git a/sway/config.c b/sway/config.c index f5efa98a..8c8c148d 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -924,23 +924,18 @@ void config_add_swaynag_warning(char *fmt, ...) { | |||
924 | if (config->reading && !config->validating) { | 924 | if (config->reading && !config->validating) { |
925 | va_list args; | 925 | va_list args; |
926 | va_start(args, fmt); | 926 | va_start(args, fmt); |
927 | size_t length = vsnprintf(NULL, 0, fmt, args) + 1; | 927 | char *str = vformat_str(fmt, args); |
928 | va_end(args); | 928 | va_end(args); |
929 | 929 | if (str == NULL) { | |
930 | char *temp = malloc(length + 1); | ||
931 | if (!temp) { | ||
932 | sway_log(SWAY_ERROR, "Failed to allocate buffer for warning."); | ||
933 | return; | 930 | return; |
934 | } | 931 | } |
935 | 932 | ||
936 | va_start(args, fmt); | ||
937 | vsnprintf(temp, length, fmt, args); | ||
938 | va_end(args); | ||
939 | |||
940 | swaynag_log(config->swaynag_command, &config->swaynag_config_errors, | 933 | swaynag_log(config->swaynag_command, &config->swaynag_config_errors, |
941 | "Warning on line %i (%s) '%s': %s", | 934 | "Warning on line %i (%s) '%s': %s", |
942 | config->current_config_line_number, config->current_config_path, | 935 | config->current_config_line_number, config->current_config_path, |
943 | config->current_config_line, temp); | 936 | config->current_config_line, str); |
937 | |||
938 | free(str); | ||
944 | } | 939 | } |
945 | } | 940 | } |
946 | 941 | ||
diff --git a/sway/config/output.c b/sway/config/output.c index 45d2441b..6fb29ded 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -162,13 +162,10 @@ static void merge_id_on_name(struct output_config *oc) { | |||
162 | char id[128]; | 162 | char id[128]; |
163 | output_get_identifier(id, sizeof(id), output); | 163 | output_get_identifier(id, sizeof(id), output); |
164 | 164 | ||
165 | size_t size = snprintf(NULL, 0, "%s on %s", id, name) + 1; | 165 | char *id_on_name = format_str("%s on %s", id, name); |
166 | char *id_on_name = malloc(size); | ||
167 | if (!id_on_name) { | 166 | if (!id_on_name) { |
168 | sway_log(SWAY_ERROR, "Failed to allocate id on name string"); | ||
169 | return; | 167 | return; |
170 | } | 168 | } |
171 | snprintf(id_on_name, size, "%s on %s", id, name); | ||
172 | 169 | ||
173 | int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name); | 170 | int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name); |
174 | if (i >= 0) { | 171 | if (i >= 0) { |
@@ -633,9 +630,7 @@ static struct output_config *get_output_config(char *identifier, | |||
633 | struct output_config *oc_name = NULL; | 630 | struct output_config *oc_name = NULL; |
634 | struct output_config *oc_id = NULL; | 631 | struct output_config *oc_id = NULL; |
635 | 632 | ||
636 | size_t length = snprintf(NULL, 0, "%s on %s", identifier, name) + 1; | 633 | char *id_on_name = format_str("%s on %s", identifier, name); |
637 | char *id_on_name = malloc(length); | ||
638 | snprintf(id_on_name, length, "%s on %s", identifier, name); | ||
639 | int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name); | 634 | int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name); |
640 | if (i >= 0) { | 635 | if (i >= 0) { |
641 | oc_id_on_name = config->output_configs->items[i]; | 636 | oc_id_on_name = config->output_configs->items[i]; |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 15687993..75d055cd 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -1273,11 +1273,7 @@ uint32_t get_mouse_bindsym(const char *name, char **error) { | |||
1273 | // Get event code from name | 1273 | // Get event code from name |
1274 | int code = libevdev_event_code_from_name(EV_KEY, name); | 1274 | int code = libevdev_event_code_from_name(EV_KEY, name); |
1275 | if (code == -1) { | 1275 | if (code == -1) { |
1276 | size_t len = snprintf(NULL, 0, "Unknown event %s", name) + 1; | 1276 | *error = format_str("Unknown event %s", name); |
1277 | *error = malloc(len); | ||
1278 | if (*error) { | ||
1279 | snprintf(*error, len, "Unknown event %s", name); | ||
1280 | } | ||
1281 | return 0; | 1277 | return 0; |
1282 | } | 1278 | } |
1283 | return code; | 1279 | return code; |
@@ -1299,13 +1295,8 @@ uint32_t get_mouse_bindcode(const char *name, char **error) { | |||
1299 | } | 1295 | } |
1300 | const char *event = libevdev_event_code_get_name(EV_KEY, code); | 1296 | const char *event = libevdev_event_code_get_name(EV_KEY, code); |
1301 | if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) { | 1297 | if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) { |
1302 | size_t len = snprintf(NULL, 0, "Event code %d (%s) is not a button", | 1298 | *error = format_str("Event code %d (%s) is not a button", |
1303 | code, event ? event : "(null)") + 1; | 1299 | code, event ? event : "(null)"); |
1304 | *error = malloc(len); | ||
1305 | if (*error) { | ||
1306 | snprintf(*error, len, "Event code %d (%s) is not a button", | ||
1307 | code, event ? event : "(null)"); | ||
1308 | } | ||
1309 | return 0; | 1300 | return 0; |
1310 | } | 1301 | } |
1311 | return code; | 1302 | return code; |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index ea2cc038..1115ba5e 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -80,15 +80,7 @@ char *input_device_get_identifier(struct wlr_input_device *device) { | |||
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | const char *fmt = "%d:%d:%s"; | 83 | char *identifier = format_str("%d:%d:%s", vendor, product, name); |
84 | int len = snprintf(NULL, 0, fmt, vendor, product, name) + 1; | ||
85 | char *identifier = malloc(len); | ||
86 | if (!identifier) { | ||
87 | sway_log(SWAY_ERROR, "Unable to allocate unique input device name"); | ||
88 | return NULL; | ||
89 | } | ||
90 | |||
91 | snprintf(identifier, len, fmt, vendor, product, name); | ||
92 | free(name); | 84 | free(name); |
93 | return identifier; | 85 | return identifier; |
94 | } | 86 | } |
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 45a588ec..c3bf4fbb 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -717,23 +717,11 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | |||
717 | 717 | ||
718 | static void handle_xkb_context_log(struct xkb_context *context, | 718 | static void handle_xkb_context_log(struct xkb_context *context, |
719 | enum xkb_log_level level, const char *format, va_list args) { | 719 | enum xkb_log_level level, const char *format, va_list args) { |
720 | va_list args_copy; | 720 | char *error = vformat_str(format, args); |
721 | va_copy(args_copy, args); | ||
722 | size_t length = vsnprintf(NULL, 0, format, args_copy) + 1; | ||
723 | va_end(args_copy); | ||
724 | |||
725 | char *error = malloc(length); | ||
726 | if (!error) { | ||
727 | sway_log(SWAY_ERROR, "Failed to allocate libxkbcommon log message"); | ||
728 | return; | ||
729 | } | ||
730 | 721 | ||
731 | va_copy(args_copy, args); | 722 | size_t len = strlen(error); |
732 | vsnprintf(error, length, format, args_copy); | 723 | if (error[len - 1] == '\n') { |
733 | va_end(args_copy); | 724 | error[len - 1] = '\0'; |
734 | |||
735 | if (error[length - 2] == '\n') { | ||
736 | error[length - 2] = '\0'; | ||
737 | } | 725 | } |
738 | 726 | ||
739 | sway_log_importance_t importance = SWAY_DEBUG; | 727 | sway_log_importance_t importance = SWAY_DEBUG; |
@@ -768,13 +756,8 @@ struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, | |||
768 | if (!keymap_file) { | 756 | if (!keymap_file) { |
769 | sway_log_errno(SWAY_ERROR, "cannot read xkb file %s", ic->xkb_file); | 757 | sway_log_errno(SWAY_ERROR, "cannot read xkb file %s", ic->xkb_file); |
770 | if (error) { | 758 | if (error) { |
771 | size_t len = snprintf(NULL, 0, "cannot read xkb file %s: %s", | 759 | *error = format_str("cannot read xkb file %s: %s", |
772 | ic->xkb_file, strerror(errno)) + 1; | 760 | ic->xkb_file, strerror(errno)); |
773 | *error = malloc(len); | ||
774 | if (*error) { | ||
775 | snprintf(*error, len, "cannot read xkb_file %s: %s", | ||
776 | ic->xkb_file, strerror(errno)); | ||
777 | } | ||
778 | } | 761 | } |
779 | goto cleanup; | 762 | goto cleanup; |
780 | } | 763 | } |
diff --git a/sway/swaynag.c b/sway/swaynag.c index 4a0a6d30..6031174d 100644 --- a/sway/swaynag.c +++ b/sway/swaynag.c | |||
@@ -145,22 +145,16 @@ void swaynag_log(const char *swaynag_command, struct swaynag_instance *swaynag, | |||
145 | 145 | ||
146 | va_list args; | 146 | va_list args; |
147 | va_start(args, fmt); | 147 | va_start(args, fmt); |
148 | size_t length = vsnprintf(NULL, 0, fmt, args) + 1; | 148 | char *str = vformat_str(fmt, args); |
149 | va_end(args); | 149 | va_end(args); |
150 | 150 | if (!str) { | |
151 | char *temp = malloc(length + 1); | ||
152 | if (!temp) { | ||
153 | sway_log(SWAY_ERROR, "Failed to allocate buffer for swaynag log entry."); | 151 | sway_log(SWAY_ERROR, "Failed to allocate buffer for swaynag log entry."); |
154 | return; | 152 | return; |
155 | } | 153 | } |
156 | 154 | ||
157 | va_start(args, fmt); | 155 | write(swaynag->fd[1], str, strlen(str)); |
158 | vsnprintf(temp, length, fmt, args); | ||
159 | va_end(args); | ||
160 | |||
161 | write(swaynag->fd[1], temp, length); | ||
162 | 156 | ||
163 | free(temp); | 157 | free(str); |
164 | } | 158 | } |
165 | 159 | ||
166 | void swaynag_show(struct swaynag_instance *swaynag) { | 160 | void swaynag_show(struct swaynag_instance *swaynag) { |
diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c index ddf2416d..eea2caa5 100644 --- a/swaybar/tray/host.c +++ b/swaybar/tray/host.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "swaybar/tray/tray.h" | 10 | #include "swaybar/tray/tray.h" |
11 | #include "list.h" | 11 | #include "list.h" |
12 | #include "log.h" | 12 | #include "log.h" |
13 | #include "stringop.h" | ||
13 | 14 | ||
14 | static const char *watcher_path = "/StatusNotifierWatcher"; | 15 | static const char *watcher_path = "/StatusNotifierWatcher"; |
15 | 16 | ||
@@ -138,12 +139,10 @@ static int handle_new_watcher(sd_bus_message *msg, | |||
138 | 139 | ||
139 | bool init_host(struct swaybar_host *host, char *protocol, | 140 | bool init_host(struct swaybar_host *host, char *protocol, |
140 | struct swaybar_tray *tray) { | 141 | struct swaybar_tray *tray) { |
141 | size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1; | 142 | host->watcher_interface = format_str("org.%s.StatusNotifierWatcher", protocol); |
142 | host->watcher_interface = malloc(len); | ||
143 | if (!host->watcher_interface) { | 143 | if (!host->watcher_interface) { |
144 | return false; | 144 | return false; |
145 | } | 145 | } |
146 | snprintf(host->watcher_interface, len, "org.%s.StatusNotifierWatcher", protocol); | ||
147 | 146 | ||
148 | sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL, *watcher_slot = NULL; | 147 | sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL, *watcher_slot = NULL; |
149 | int ret = sd_bus_match_signal(tray->bus, ®_slot, host->watcher_interface, | 148 | int ret = sd_bus_match_signal(tray->bus, ®_slot, host->watcher_interface, |
@@ -173,13 +172,10 @@ bool init_host(struct swaybar_host *host, char *protocol, | |||
173 | } | 172 | } |
174 | 173 | ||
175 | pid_t pid = getpid(); | 174 | pid_t pid = getpid(); |
176 | size_t service_len = snprintf(NULL, 0, "org.%s.StatusNotifierHost-%d", | 175 | host->service = format_str("org.%s.StatusNotifierHost-%d", protocol, pid); |
177 | protocol, pid) + 1; | ||
178 | host->service = malloc(service_len); | ||
179 | if (!host->service) { | 176 | if (!host->service) { |
180 | goto error; | 177 | goto error; |
181 | } | 178 | } |
182 | snprintf(host->service, service_len, "org.%s.StatusNotifierHost-%d", protocol, pid); | ||
183 | ret = sd_bus_request_name(tray->bus, host->service, 0); | 179 | ret = sd_bus_request_name(tray->bus, host->service, 0); |
184 | if (ret < 0) { | 180 | if (ret < 0) { |
185 | sway_log(SWAY_DEBUG, "Failed to acquire service name: %s", strerror(-ret)); | 181 | sway_log(SWAY_DEBUG, "Failed to acquire service name: %s", strerror(-ret)); |
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c index c426c3d4..b513dca5 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/tray/icon.c | |||
@@ -40,9 +40,7 @@ static list_t *get_basedirs(void) { | |||
40 | data_dirs = strdup(data_dirs); | 40 | data_dirs = strdup(data_dirs); |
41 | char *dir = strtok(data_dirs, ":"); | 41 | char *dir = strtok(data_dirs, ":"); |
42 | do { | 42 | do { |
43 | size_t path_len = snprintf(NULL, 0, "%s/icons", dir) + 1; | 43 | char *path = format_str("%s/icons", dir); |
44 | char *path = malloc(path_len); | ||
45 | snprintf(path, path_len, "%s/icons", dir); | ||
46 | list_add(basedirs, path); | 44 | list_add(basedirs, path); |
47 | } while ((dir = strtok(NULL, ":"))); | 45 | } while ((dir = strtok(NULL, ":"))); |
48 | free(data_dirs); | 46 | free(data_dirs); |
@@ -206,13 +204,7 @@ static const char *entry_handler(char *group, char *key, char *value, | |||
206 | */ | 204 | */ |
207 | static struct icon_theme *read_theme_file(char *basedir, char *theme_name) { | 205 | static struct icon_theme *read_theme_file(char *basedir, char *theme_name) { |
208 | // look for index.theme file | 206 | // look for index.theme file |
209 | size_t path_len = snprintf(NULL, 0, "%s/%s/index.theme", basedir, | 207 | char *path = format_str("%s/%s/index.theme", basedir, theme_name); |
210 | theme_name) + 1; | ||
211 | char *path = malloc(path_len); | ||
212 | if (!path) { | ||
213 | return NULL; | ||
214 | } | ||
215 | snprintf(path, path_len, "%s/%s/index.theme", basedir, theme_name); | ||
216 | FILE *theme_file = fopen(path, "r"); | 208 | FILE *theme_file = fopen(path, "r"); |
217 | free(path); | 209 | free(path); |
218 | if (!theme_file) { | 210 | if (!theme_file) { |
@@ -416,26 +408,20 @@ static char *find_icon_in_subdir(char *name, char *basedir, char *theme, | |||
416 | #endif | 408 | #endif |
417 | }; | 409 | }; |
418 | 410 | ||
419 | size_t path_len = snprintf(NULL, 0, "%s/%s/%s/%s.EXT", basedir, theme, | ||
420 | subdir, name) + 1; | ||
421 | char *path = malloc(path_len); | ||
422 | |||
423 | for (size_t i = 0; i < sizeof(extensions) / sizeof(*extensions); ++i) { | 411 | for (size_t i = 0; i < sizeof(extensions) / sizeof(*extensions); ++i) { |
424 | snprintf(path, path_len, "%s/%s/%s/%s.%s", basedir, theme, subdir, | 412 | char *path = format_str("%s/%s/%s/%s.%s", |
425 | name, extensions[i]); | 413 | basedir, theme, subdir, name, extensions[i]); |
426 | if (access(path, R_OK) == 0) { | 414 | if (access(path, R_OK) == 0) { |
427 | return path; | 415 | return path; |
428 | } | 416 | } |
417 | free(path); | ||
429 | } | 418 | } |
430 | 419 | ||
431 | free(path); | ||
432 | return NULL; | 420 | return NULL; |
433 | } | 421 | } |
434 | 422 | ||
435 | static bool theme_exists_in_basedir(char *theme, char *basedir) { | 423 | static bool theme_exists_in_basedir(char *theme, char *basedir) { |
436 | size_t path_len = snprintf(NULL, 0, "%s/%s", basedir, theme) + 1; | 424 | char *path = format_str("%s/%s", basedir, theme); |
437 | char *path = malloc(path_len); | ||
438 | snprintf(path, path_len, "%s/%s", basedir, theme); | ||
439 | bool ret = dir_exists(path); | 425 | bool ret = dir_exists(path); |
440 | free(path); | 426 | free(path); |
441 | return ret; | 427 | return ret; |
diff --git a/swaybar/tray/watcher.c b/swaybar/tray/watcher.c index 16afc27c..551e1d12 100644 --- a/swaybar/tray/watcher.c +++ b/swaybar/tray/watcher.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include "list.h" | 7 | #include "list.h" |
8 | #include "log.h" | 8 | #include "log.h" |
9 | #include "stringop.h" | ||
9 | #include "swaybar/tray/watcher.h" | 10 | #include "swaybar/tray/watcher.h" |
10 | 11 | ||
11 | static const char *obj_path = "/StatusNotifierWatcher"; | 12 | static const char *obj_path = "/StatusNotifierWatcher"; |
@@ -76,9 +77,7 @@ static int register_sni(sd_bus_message *msg, void *data, sd_bus_error *error) { | |||
76 | service = service_or_path; | 77 | service = service_or_path; |
77 | path = "/StatusNotifierItem"; | 78 | path = "/StatusNotifierItem"; |
78 | } | 79 | } |
79 | size_t id_len = snprintf(NULL, 0, "%s%s", service, path) + 1; | 80 | id = format_str("%s%s", service, path); |
80 | id = malloc(id_len); | ||
81 | snprintf(id, id_len, "%s%s", service, path); | ||
82 | } | 81 | } |
83 | 82 | ||
84 | if (list_seq_find(watcher->items, cmp_id, id) == -1) { | 83 | if (list_seq_find(watcher->items, cmp_id, id) == -1) { |
@@ -159,9 +158,7 @@ struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus) { | |||
159 | return NULL; | 158 | return NULL; |
160 | } | 159 | } |
161 | 160 | ||
162 | size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1; | 161 | watcher->interface = format_str("org.%s.StatusNotifierWatcher", protocol); |
163 | watcher->interface = malloc(len); | ||
164 | snprintf(watcher->interface, len, "org.%s.StatusNotifierWatcher", protocol); | ||
165 | 162 | ||
166 | sd_bus_slot *signal_slot = NULL, *vtable_slot = NULL; | 163 | sd_bus_slot *signal_slot = NULL, *vtable_slot = NULL; |
167 | int ret = sd_bus_add_object_vtable(bus, &vtable_slot, obj_path, | 164 | int ret = sd_bus_add_object_vtable(bus, &vtable_slot, obj_path, |