Codebase list i3-gaps / c85d16f
Use safe wrappers wherever possible shdown 8 years ago
14 changed file(s) with 31 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
767767 switch (o) {
768768 case 's':
769769 FREE(socket_path);
770 socket_path = strdup(optarg);
770 socket_path = sstrdup(optarg);
771771 break;
772772 case 'v':
773773 printf("i3-config-wizard " I3_VERSION "\n");
102102 *
103103 */
104104 static uint8_t *concat_strings(char **glyphs, int max) {
105 uint8_t *output = calloc(max + 1, 4);
105 uint8_t *output = scalloc(max + 1, 4);
106106 uint8_t *walk = output;
107107 for (int c = 0; c < max; c++) {
108108 printf("at %c\n", glyphs[c][0]);
186186
187187 /* allocate space for the output */
188188 int inputlen = strlen(command);
189 char *full = calloc(1,
190 strlen(format) - (2 * cnt) /* format without all %s */
191 + (inputlen * cnt) /* replaced %s */
192 + 1); /* trailing NUL */
189 char *full = scalloc(strlen(format) - (2 * cnt) /* format without all %s */
190 + (inputlen * cnt) /* replaced %s */
191 + 1, /* trailing NUL */
192 1);
193193 char *dest = full;
194194 for (c = 0; c < len; c++) {
195195 /* if this is not % or it is % but without a following 's',
358358 }
359359
360360 int main(int argc, char *argv[]) {
361 format = strdup("%s");
361 format = sstrdup("%s");
362362 socket_path = getenv("I3SOCK");
363363 char *pattern = sstrdup("pango:monospace 8");
364364 int o, option_index = 0;
380380 switch (o) {
381381 case 's':
382382 FREE(socket_path);
383 socket_path = strdup(optarg);
383 socket_path = sstrdup(optarg);
384384 break;
385385 case 'v':
386386 printf("i3-input " I3_VERSION);
400400 break;
401401 case 'f':
402402 FREE(pattern);
403 pattern = strdup(optarg);
403 pattern = sstrdup(optarg);
404404 break;
405405 case 'F':
406406 FREE(format);
407 format = strdup(optarg);
407 format = sstrdup(optarg);
408408 break;
409409 case 'h':
410410 printf("i3-input " I3_VERSION "\n");
186186 payload = sstrdup(argv[optind]);
187187 } else {
188188 char *both;
189 if (asprintf(&both, "%s %s", payload, argv[optind]) == -1)
190 err(EXIT_FAILURE, "asprintf");
189 sasprintf(&both, "%s %s", payload, argv[optind]);
191190 free(payload);
192191 payload = both;
193192 }
370370 if (argv0_len > strlen(".nagbar_cmd") &&
371371 strcmp(argv[0] + argv0_len - strlen(".nagbar_cmd"), ".nagbar_cmd") == 0) {
372372 unlink(argv[0]);
373 cmd = strdup(argv[0]);
373 cmd = sstrdup(argv[0]);
374374 *(cmd + argv0_len - strlen(".nagbar_cmd")) = '\0';
375375 execl("/bin/sh", "/bin/sh", cmd, NULL);
376376 err(EXIT_FAILURE, "execv(/bin/sh, /bin/sh, %s)", cmd);
417417 printf("i3-nagbar [-m <message>] [-b <button> <action>] [-t warning|error] [-f <font>] [-v]\n");
418418 return 0;
419419 case 'b':
420 buttons = realloc(buttons, sizeof(button_t) * (buttoncnt + 1));
420 buttons = srealloc(buttons, sizeof(button_t) * (buttoncnt + 1));
421421 buttons[buttoncnt].label = i3string_from_utf8(optarg);
422422 buttons[buttoncnt].action = argv[optind];
423423 printf("button with label *%s* and action *%s*\n",
219219 return 1;
220220 }
221221 if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
222 char *copy = (char *)malloc(len + 1);
222 char *copy = (char *)smalloc(len + 1);
223223 strncpy(copy, (const char *)val, len);
224224 copy[len] = 0;
225225 ctx->block.min_width_str = copy;
226226 return 1;
227227 }
228228 if (strcasecmp(ctx->last_map_key, "name") == 0) {
229 char *copy = (char *)malloc(len + 1);
229 char *copy = (char *)smalloc(len + 1);
230230 strncpy(copy, (const char *)val, len);
231231 copy[len] = 0;
232232 ctx->block.name = copy;
233233 return 1;
234234 }
235235 if (strcasecmp(ctx->last_map_key, "instance") == 0) {
236 char *copy = (char *)malloc(len + 1);
236 char *copy = (char *)smalloc(len + 1);
237237 strncpy(copy, (const char *)val, len);
238238 copy[len] = 0;
239239 ctx->block.instance = copy;
16531653 "i3bar\0i3bar\0");
16541654
16551655 char *name;
1656 if (asprintf(&name, "i3bar for output %s", walk->name) == -1)
1657 err(EXIT_FAILURE, "asprintf()");
1656 sasprintf(&name, "i3bar for output %s", walk->name);
16581657 xcb_void_cookie_t name_cookie;
16591658 name_cookie = xcb_change_property(xcb_connection,
16601659 XCB_PROP_MODE_REPLACE,
7272 }
7373 sasprintf(&path, ":%s", tmp);
7474 } else {
75 path = strdup(path);
75 path = sstrdup(path);
7676 }
7777 const char *component;
7878 char *str = path;
7979 if (prop_reply->type == XCB_ATOM_CARDINAL) {
8080 /* We treat a CARDINAL as a >= 32-bit unsigned int. The only CARDINAL
8181 * we query is I3_PID, which is 32-bit. */
82 if (asprintf(&content, "%u", *((unsigned int *)xcb_get_property_value(prop_reply))) == -1) {
83 free(atom_reply);
84 free(prop_reply);
85 return NULL;
86 }
82 sasprintf(&content, "%u", *((unsigned int *)xcb_get_property_value(prop_reply)));
8783 } else {
88 if (asprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply),
89 (char *)xcb_get_property_value(prop_reply)) == -1) {
90 free(atom_reply);
91 free(prop_reply);
92 return NULL;
93 }
84 sasprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply),
85 (char *)xcb_get_property_value(prop_reply));
9486 }
9587 if (provided_conn == NULL)
9688 xcb_disconnect(conn);
392392 Binding *ret = smalloc(sizeof(Binding));
393393 *ret = *bind;
394394 if (bind->symbol != NULL)
395 ret->symbol = strdup(bind->symbol);
395 ret->symbol = sstrdup(bind->symbol);
396396 if (bind->command != NULL)
397 ret->command = strdup(bind->command);
397 ret->command = sstrdup(bind->command);
398398 if (bind->translated_to != NULL) {
399399 ret->translated_to = smalloc(sizeof(xcb_keycode_t) * bind->number_keycodes);
400400 memcpy(ret->translated_to, bind->translated_to, sizeof(xcb_keycode_t) * bind->number_keycodes);
788788
789789 /* read the script’s output */
790790 int conv_size = 65535;
791 char *converted = malloc(conv_size);
791 char *converted = smalloc(conv_size);
792792 int read_bytes = 0, ret;
793793 do {
794794 if (read_bytes == conv_size) {
795795 conv_size += 65535;
796 converted = realloc(converted, conv_size);
796 converted = srealloc(converted, conv_size);
797797 }
798798 ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
799799 if (ret == -1) {
899899 int event = client->num_events;
900900
901901 client->num_events++;
902 client->events = realloc(client->events, client->num_events * sizeof(char *));
902 client->events = srealloc(client->events, client->num_events * sizeof(char *));
903903 /* We copy the string because it is not null-terminated and strndup()
904904 * is missing on some BSD systems */
905905 client->events[event] = scalloc(len + 1, 1);
315315 }
316316
317317 char *startup_id;
318 if (asprintf(&startup_id, "%.*s", xcb_get_property_value_length(startup_id_reply),
319 (char *)xcb_get_property_value(startup_id_reply)) == -1) {
320 perror("asprintf()");
321 DLOG("Could not get _NET_STARTUP_ID\n");
322 free(startup_id_reply);
323 return NULL;
324 }
325
318 sasprintf(&startup_id, "%.*s", xcb_get_property_value_length(startup_id_reply),
319 (char *)xcb_get_property_value(startup_id_reply));
326320 struct Startup_Sequence *current, *sequence = NULL;
327321 TAILQ_FOREACH(current, &startup_sequences, sequences) {
328322 if (strcmp(current->id, startup_id) != 0)
121121 /* if the script is not in path, maybe the user installed to a strange
122122 * location and runs the i3 binary with an absolute path. We use
123123 * argv[0]’s dirname */
124 char *pathbuf = strdup(start_argv[0]);
124 char *pathbuf = sstrdup(start_argv[0]);
125125 char *dir = dirname(pathbuf);
126126 sasprintf(&migratepath, "%s/%s", dir, name);
127127 argv[0] = migratepath;
207207 }
208208
209209 char *new_role;
210 if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
211 (char *)xcb_get_property_value(prop)) == -1) {
212 perror("asprintf()");
213 DLOG("Could not get WM_WINDOW_ROLE\n");
214 free(prop);
215 return;
216 }
210 sasprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
211 (char *)xcb_get_property_value(prop));
217212 FREE(win->role);
218213 win->role = new_role;
219214 LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);