mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 06:05:58 +01:00
examples/text-input: stop using strcpy/strcat
These functions are too easy to misuse, they don't do bounds checking.
This commit is contained in:
parent
2b10ae62ad
commit
366e8e3b91
1 changed files with 6 additions and 6 deletions
|
@ -244,15 +244,15 @@ static void text_input_handle_done(void *data,
|
||||||
buffer[strlen(buffer) - delete_before] = '\0';
|
buffer[strlen(buffer) - delete_before] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
char *commit_string = current.commit;
|
const char *commit_string = current.commit;
|
||||||
if (!commit_string) {
|
if (!commit_string) {
|
||||||
commit_string = "";
|
commit_string = "";
|
||||||
}
|
}
|
||||||
char *old_buffer = buffer;
|
size_t new_size = strlen(buffer) + strlen(commit_string) + 1;
|
||||||
buffer = calloc(strlen(buffer) + strlen(commit_string) + 1, sizeof(char)); // realloc may fail anyway
|
char *new_buffer = calloc(new_size, sizeof(char)); // realloc may fail anyway
|
||||||
strcpy(buffer, old_buffer);
|
snprintf(new_buffer, new_size, "%s%s", buffer, commit_string);
|
||||||
free(old_buffer);
|
free(buffer);
|
||||||
strcat(buffer, commit_string);
|
buffer = new_buffer;
|
||||||
|
|
||||||
send_status_update(zwp_text_input_v3);
|
send_status_update(zwp_text_input_v3);
|
||||||
show_status();
|
show_status();
|
||||||
|
|
Loading…
Reference in a new issue