diff options
author | Simon Ser <contact@emersion.fr> | 2022-06-04 23:02:42 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-06-04 23:02:42 +0200 |
commit | 366e8e3b9163d29bfcb75c97d482aa730d0dfc11 (patch) | |
tree | eb0cef915a22852cf559b70cea5d86598aa70e6e /examples | |
parent | 2b10ae62ad9c1a3de5d96dafbf0f86a9e897fc8e (diff) |
examples/text-input: stop using strcpy/strcat
These functions are too easy to misuse, they don't do bounds
checking.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/text-input.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/text-input.c b/examples/text-input.c index 36363275..2f530d27 100644 --- a/examples/text-input.c +++ b/examples/text-input.c @@ -244,15 +244,15 @@ static void text_input_handle_done(void *data, buffer[strlen(buffer) - delete_before] = '\0'; } - char *commit_string = current.commit; + const char *commit_string = current.commit; if (!commit_string) { commit_string = ""; } - char *old_buffer = buffer; - buffer = calloc(strlen(buffer) + strlen(commit_string) + 1, sizeof(char)); // realloc may fail anyway - strcpy(buffer, old_buffer); - free(old_buffer); - strcat(buffer, commit_string); + size_t new_size = strlen(buffer) + strlen(commit_string) + 1; + char *new_buffer = calloc(new_size, sizeof(char)); // realloc may fail anyway + snprintf(new_buffer, new_size, "%s%s", buffer, commit_string); + free(buffer); + buffer = new_buffer; send_status_update(zwp_text_input_v3); show_status(); |