Use safe wrappers wherever possible
shdown
8 years ago
767 | 767 |
switch (o) {
|
768 | 768 |
case 's':
|
769 | 769 |
FREE(socket_path);
|
770 | |
socket_path = strdup(optarg);
|
|
770 |
socket_path = sstrdup(optarg);
|
771 | 771 |
break;
|
772 | 772 |
case 'v':
|
773 | 773 |
printf("i3-config-wizard " I3_VERSION "\n");
|
102 | 102 |
*
|
103 | 103 |
*/
|
104 | 104 |
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);
|
106 | 106 |
uint8_t *walk = output;
|
107 | 107 |
for (int c = 0; c < max; c++) {
|
108 | 108 |
printf("at %c\n", glyphs[c][0]);
|
|
186 | 186 |
|
187 | 187 |
/* allocate space for the output */
|
188 | 188 |
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);
|
193 | 193 |
char *dest = full;
|
194 | 194 |
for (c = 0; c < len; c++) {
|
195 | 195 |
/* if this is not % or it is % but without a following 's',
|
|
358 | 358 |
}
|
359 | 359 |
|
360 | 360 |
int main(int argc, char *argv[]) {
|
361 | |
format = strdup("%s");
|
|
361 |
format = sstrdup("%s");
|
362 | 362 |
socket_path = getenv("I3SOCK");
|
363 | 363 |
char *pattern = sstrdup("pango:monospace 8");
|
364 | 364 |
int o, option_index = 0;
|
|
380 | 380 |
switch (o) {
|
381 | 381 |
case 's':
|
382 | 382 |
FREE(socket_path);
|
383 | |
socket_path = strdup(optarg);
|
|
383 |
socket_path = sstrdup(optarg);
|
384 | 384 |
break;
|
385 | 385 |
case 'v':
|
386 | 386 |
printf("i3-input " I3_VERSION);
|
|
400 | 400 |
break;
|
401 | 401 |
case 'f':
|
402 | 402 |
FREE(pattern);
|
403 | |
pattern = strdup(optarg);
|
|
403 |
pattern = sstrdup(optarg);
|
404 | 404 |
break;
|
405 | 405 |
case 'F':
|
406 | 406 |
FREE(format);
|
407 | |
format = strdup(optarg);
|
|
407 |
format = sstrdup(optarg);
|
408 | 408 |
break;
|
409 | 409 |
case 'h':
|
410 | 410 |
printf("i3-input " I3_VERSION "\n");
|
186 | 186 |
payload = sstrdup(argv[optind]);
|
187 | 187 |
} else {
|
188 | 188 |
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]);
|
191 | 190 |
free(payload);
|
192 | 191 |
payload = both;
|
193 | 192 |
}
|
370 | 370 |
if (argv0_len > strlen(".nagbar_cmd") &&
|
371 | 371 |
strcmp(argv[0] + argv0_len - strlen(".nagbar_cmd"), ".nagbar_cmd") == 0) {
|
372 | 372 |
unlink(argv[0]);
|
373 | |
cmd = strdup(argv[0]);
|
|
373 |
cmd = sstrdup(argv[0]);
|
374 | 374 |
*(cmd + argv0_len - strlen(".nagbar_cmd")) = '\0';
|
375 | 375 |
execl("/bin/sh", "/bin/sh", cmd, NULL);
|
376 | 376 |
err(EXIT_FAILURE, "execv(/bin/sh, /bin/sh, %s)", cmd);
|
|
417 | 417 |
printf("i3-nagbar [-m <message>] [-b <button> <action>] [-t warning|error] [-f <font>] [-v]\n");
|
418 | 418 |
return 0;
|
419 | 419 |
case 'b':
|
420 | |
buttons = realloc(buttons, sizeof(button_t) * (buttoncnt + 1));
|
|
420 |
buttons = srealloc(buttons, sizeof(button_t) * (buttoncnt + 1));
|
421 | 421 |
buttons[buttoncnt].label = i3string_from_utf8(optarg);
|
422 | 422 |
buttons[buttoncnt].action = argv[optind];
|
423 | 423 |
printf("button with label *%s* and action *%s*\n",
|
219 | 219 |
return 1;
|
220 | 220 |
}
|
221 | 221 |
if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
|
222 | |
char *copy = (char *)malloc(len + 1);
|
|
222 |
char *copy = (char *)smalloc(len + 1);
|
223 | 223 |
strncpy(copy, (const char *)val, len);
|
224 | 224 |
copy[len] = 0;
|
225 | 225 |
ctx->block.min_width_str = copy;
|
226 | 226 |
return 1;
|
227 | 227 |
}
|
228 | 228 |
if (strcasecmp(ctx->last_map_key, "name") == 0) {
|
229 | |
char *copy = (char *)malloc(len + 1);
|
|
229 |
char *copy = (char *)smalloc(len + 1);
|
230 | 230 |
strncpy(copy, (const char *)val, len);
|
231 | 231 |
copy[len] = 0;
|
232 | 232 |
ctx->block.name = copy;
|
233 | 233 |
return 1;
|
234 | 234 |
}
|
235 | 235 |
if (strcasecmp(ctx->last_map_key, "instance") == 0) {
|
236 | |
char *copy = (char *)malloc(len + 1);
|
|
236 |
char *copy = (char *)smalloc(len + 1);
|
237 | 237 |
strncpy(copy, (const char *)val, len);
|
238 | 238 |
copy[len] = 0;
|
239 | 239 |
ctx->block.instance = copy;
|
1653 | 1653 |
"i3bar\0i3bar\0");
|
1654 | 1654 |
|
1655 | 1655 |
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);
|
1658 | 1657 |
xcb_void_cookie_t name_cookie;
|
1659 | 1658 |
name_cookie = xcb_change_property(xcb_connection,
|
1660 | 1659 |
XCB_PROP_MODE_REPLACE,
|
72 | 72 |
}
|
73 | 73 |
sasprintf(&path, ":%s", tmp);
|
74 | 74 |
} else {
|
75 | |
path = strdup(path);
|
|
75 |
path = sstrdup(path);
|
76 | 76 |
}
|
77 | 77 |
const char *component;
|
78 | 78 |
char *str = path;
|
79 | 79 |
if (prop_reply->type == XCB_ATOM_CARDINAL) {
|
80 | 80 |
/* We treat a CARDINAL as a >= 32-bit unsigned int. The only CARDINAL
|
81 | 81 |
* 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)));
|
87 | 83 |
} 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));
|
94 | 86 |
}
|
95 | 87 |
if (provided_conn == NULL)
|
96 | 88 |
xcb_disconnect(conn);
|
392 | 392 |
Binding *ret = smalloc(sizeof(Binding));
|
393 | 393 |
*ret = *bind;
|
394 | 394 |
if (bind->symbol != NULL)
|
395 | |
ret->symbol = strdup(bind->symbol);
|
|
395 |
ret->symbol = sstrdup(bind->symbol);
|
396 | 396 |
if (bind->command != NULL)
|
397 | |
ret->command = strdup(bind->command);
|
|
397 |
ret->command = sstrdup(bind->command);
|
398 | 398 |
if (bind->translated_to != NULL) {
|
399 | 399 |
ret->translated_to = smalloc(sizeof(xcb_keycode_t) * bind->number_keycodes);
|
400 | 400 |
memcpy(ret->translated_to, bind->translated_to, sizeof(xcb_keycode_t) * bind->number_keycodes);
|
788 | 788 |
|
789 | 789 |
/* read the script’s output */
|
790 | 790 |
int conv_size = 65535;
|
791 | |
char *converted = malloc(conv_size);
|
|
791 |
char *converted = smalloc(conv_size);
|
792 | 792 |
int read_bytes = 0, ret;
|
793 | 793 |
do {
|
794 | 794 |
if (read_bytes == conv_size) {
|
795 | 795 |
conv_size += 65535;
|
796 | |
converted = realloc(converted, conv_size);
|
|
796 |
converted = srealloc(converted, conv_size);
|
797 | 797 |
}
|
798 | 798 |
ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
|
799 | 799 |
if (ret == -1) {
|
899 | 899 |
int event = client->num_events;
|
900 | 900 |
|
901 | 901 |
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 *));
|
903 | 903 |
/* We copy the string because it is not null-terminated and strndup()
|
904 | 904 |
* is missing on some BSD systems */
|
905 | 905 |
client->events[event] = scalloc(len + 1, 1);
|
315 | 315 |
}
|
316 | 316 |
|
317 | 317 |
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));
|
326 | 320 |
struct Startup_Sequence *current, *sequence = NULL;
|
327 | 321 |
TAILQ_FOREACH(current, &startup_sequences, sequences) {
|
328 | 322 |
if (strcmp(current->id, startup_id) != 0)
|
121 | 121 |
/* if the script is not in path, maybe the user installed to a strange
|
122 | 122 |
* location and runs the i3 binary with an absolute path. We use
|
123 | 123 |
* argv[0]’s dirname */
|
124 | |
char *pathbuf = strdup(start_argv[0]);
|
|
124 |
char *pathbuf = sstrdup(start_argv[0]);
|
125 | 125 |
char *dir = dirname(pathbuf);
|
126 | 126 |
sasprintf(&migratepath, "%s/%s", dir, name);
|
127 | 127 |
argv[0] = migratepath;
|
207 | 207 |
}
|
208 | 208 |
|
209 | 209 |
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));
|
217 | 212 |
FREE(win->role);
|
218 | 213 |
win->role = new_role;
|
219 | 214 |
LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);
|