Use safe wrappers wherever possible
This commit is contained in:
@ -393,9 +393,9 @@ static Binding *binding_copy(Binding *bind) {
|
||||
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);
|
||||
|
@ -789,12 +789,12 @@ static char *migrate_config(char *input, off_t size) {
|
||||
|
||||
/* 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) {
|
||||
|
@ -900,7 +900,7 @@ static int add_subscription(void *extra, const unsigned char *s,
|
||||
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);
|
||||
|
@ -316,14 +316,8 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -122,7 +122,7 @@ void exec_i3_utility(char *name, char *argv[]) {
|
||||
/* 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;
|
||||
|
@ -208,13 +208,8 @@ void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool befo
|
||||
}
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user