switch (o) {
case 's':
FREE(socket_path);
- socket_path = strdup(optarg);
+ socket_path = sstrdup(optarg);
break;
case 'v':
printf("i3-config-wizard " I3_VERSION "\n");
*
*/
static uint8_t *concat_strings(char **glyphs, int max) {
- uint8_t *output = calloc(max + 1, 4);
+ uint8_t *output = scalloc(max + 1, 4);
uint8_t *walk = output;
for (int c = 0; c < max; c++) {
printf("at %c\n", glyphs[c][0]);
/* allocate space for the output */
int inputlen = strlen(command);
- char *full = calloc(1,
- strlen(format) - (2 * cnt) /* format without all %s */
- + (inputlen * cnt) /* replaced %s */
- + 1); /* trailing NUL */
+ char *full = scalloc(strlen(format) - (2 * cnt) /* format without all %s */
+ + (inputlen * cnt) /* replaced %s */
+ + 1, /* trailing NUL */
+ 1);
char *dest = full;
for (c = 0; c < len; c++) {
/* if this is not % or it is % but without a following 's',
}
int main(int argc, char *argv[]) {
- format = strdup("%s");
+ format = sstrdup("%s");
socket_path = getenv("I3SOCK");
char *pattern = sstrdup("pango:monospace 8");
int o, option_index = 0;
switch (o) {
case 's':
FREE(socket_path);
- socket_path = strdup(optarg);
+ socket_path = sstrdup(optarg);
break;
case 'v':
printf("i3-input " I3_VERSION);
break;
case 'f':
FREE(pattern);
- pattern = strdup(optarg);
+ pattern = sstrdup(optarg);
break;
case 'F':
FREE(format);
- format = strdup(optarg);
+ format = sstrdup(optarg);
break;
case 'h':
printf("i3-input " I3_VERSION "\n");
payload = sstrdup(argv[optind]);
} else {
char *both;
- if (asprintf(&both, "%s %s", payload, argv[optind]) == -1)
- err(EXIT_FAILURE, "asprintf");
+ sasprintf(&both, "%s %s", payload, argv[optind]);
free(payload);
payload = both;
}
if (argv0_len > strlen(".nagbar_cmd") &&
strcmp(argv[0] + argv0_len - strlen(".nagbar_cmd"), ".nagbar_cmd") == 0) {
unlink(argv[0]);
- cmd = strdup(argv[0]);
+ cmd = sstrdup(argv[0]);
*(cmd + argv0_len - strlen(".nagbar_cmd")) = '\0';
execl("/bin/sh", "/bin/sh", cmd, NULL);
err(EXIT_FAILURE, "execv(/bin/sh, /bin/sh, %s)", cmd);
printf("i3-nagbar [-m <message>] [-b <button> <action>] [-t warning|error] [-f <font>] [-v]\n");
return 0;
case 'b':
- buttons = realloc(buttons, sizeof(button_t) * (buttoncnt + 1));
+ buttons = srealloc(buttons, sizeof(button_t) * (buttoncnt + 1));
buttons[buttoncnt].label = i3string_from_utf8(optarg);
buttons[buttoncnt].action = argv[optind];
printf("button with label *%s* and action *%s*\n",
return 1;
}
if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
- char *copy = (char *)malloc(len + 1);
+ char *copy = (char *)smalloc(len + 1);
strncpy(copy, (const char *)val, len);
copy[len] = 0;
ctx->block.min_width_str = copy;
return 1;
}
if (strcasecmp(ctx->last_map_key, "name") == 0) {
- char *copy = (char *)malloc(len + 1);
+ char *copy = (char *)smalloc(len + 1);
strncpy(copy, (const char *)val, len);
copy[len] = 0;
ctx->block.name = copy;
return 1;
}
if (strcasecmp(ctx->last_map_key, "instance") == 0) {
- char *copy = (char *)malloc(len + 1);
+ char *copy = (char *)smalloc(len + 1);
strncpy(copy, (const char *)val, len);
copy[len] = 0;
ctx->block.instance = copy;
"i3bar\0i3bar\0");
char *name;
- if (asprintf(&name, "i3bar for output %s", walk->name) == -1)
- err(EXIT_FAILURE, "asprintf()");
+ sasprintf(&name, "i3bar for output %s", walk->name);
xcb_void_cookie_t name_cookie;
name_cookie = xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE,
}
sasprintf(&path, ":%s", tmp);
} else {
- path = strdup(path);
+ path = sstrdup(path);
}
const char *component;
char *str = path;
if (prop_reply->type == XCB_ATOM_CARDINAL) {
/* We treat a CARDINAL as a >= 32-bit unsigned int. The only CARDINAL
* we query is I3_PID, which is 32-bit. */
- if (asprintf(&content, "%u", *((unsigned int *)xcb_get_property_value(prop_reply))) == -1) {
- free(atom_reply);
- free(prop_reply);
- return NULL;
- }
+ sasprintf(&content, "%u", *((unsigned int *)xcb_get_property_value(prop_reply)));
} else {
- if (asprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply),
- (char *)xcb_get_property_value(prop_reply)) == -1) {
- free(atom_reply);
- free(prop_reply);
- return NULL;
- }
+ sasprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply),
+ (char *)xcb_get_property_value(prop_reply));
}
if (provided_conn == NULL)
xcb_disconnect(conn);
Binding *ret = smalloc(sizeof(Binding));
*ret = *bind;
if (bind->symbol != NULL)
- ret->symbol = strdup(bind->symbol);
+ ret->symbol = sstrdup(bind->symbol);
if (bind->command != NULL)
- ret->command = strdup(bind->command);
+ ret->command = sstrdup(bind->command);
if (bind->translated_to != NULL) {
ret->translated_to = smalloc(sizeof(xcb_keycode_t) * bind->number_keycodes);
memcpy(ret->translated_to, bind->translated_to, sizeof(xcb_keycode_t) * bind->number_keycodes);
/* read the script’s output */
int conv_size = 65535;
- char *converted = malloc(conv_size);
+ char *converted = smalloc(conv_size);
int read_bytes = 0, ret;
do {
if (read_bytes == conv_size) {
conv_size += 65535;
- converted = realloc(converted, conv_size);
+ converted = srealloc(converted, conv_size);
}
ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
if (ret == -1) {
int event = client->num_events;
client->num_events++;
- client->events = realloc(client->events, client->num_events * sizeof(char *));
+ client->events = srealloc(client->events, client->num_events * sizeof(char *));
/* We copy the string because it is not null-terminated and strndup()
* is missing on some BSD systems */
client->events[event] = scalloc(len + 1, 1);
}
char *startup_id;
- if (asprintf(&startup_id, "%.*s", xcb_get_property_value_length(startup_id_reply),
- (char *)xcb_get_property_value(startup_id_reply)) == -1) {
- perror("asprintf()");
- DLOG("Could not get _NET_STARTUP_ID\n");
- free(startup_id_reply);
- return NULL;
- }
-
+ sasprintf(&startup_id, "%.*s", xcb_get_property_value_length(startup_id_reply),
+ (char *)xcb_get_property_value(startup_id_reply));
struct Startup_Sequence *current, *sequence = NULL;
TAILQ_FOREACH(current, &startup_sequences, sequences) {
if (strcmp(current->id, startup_id) != 0)
/* if the script is not in path, maybe the user installed to a strange
* location and runs the i3 binary with an absolute path. We use
* argv[0]’s dirname */
- char *pathbuf = strdup(start_argv[0]);
+ char *pathbuf = sstrdup(start_argv[0]);
char *dir = dirname(pathbuf);
sasprintf(&migratepath, "%s/%s", dir, name);
argv[0] = migratepath;
}
char *new_role;
- if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
- (char *)xcb_get_property_value(prop)) == -1) {
- perror("asprintf()");
- DLOG("Could not get WM_WINDOW_ROLE\n");
- free(prop);
- return;
- }
+ sasprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
+ (char *)xcb_get_property_value(prop));
FREE(win->role);
win->role = new_role;
LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);