From f62a1e1b2c9358997da9f12edffaf2120f56f3ed Mon Sep 17 00:00:00 2001 From: dam Date: Sun, 23 Oct 2022 23:37:01 +0000 Subject: Improved string_buffer allocation. Sanitize task names on input. --- main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 733778a..0c0e767 100644 --- a/main.c +++ b/main.c @@ -79,6 +79,7 @@ char *app_folder = NULL; char *db_file_path = NULL; char *ar_file_path = NULL; char *string_buffer = NULL; +size_t string_buffer_size = 0; int size_x, size_y, pos_x, pos_y; @@ -1168,7 +1169,11 @@ int main(int argc, char *argv[]) { clear(); getmaxyx(stdscr, size_y, size_x); is_valid_window = size_x >= 60 && size_y >= 3; - string_buffer = realloc(string_buffer, 511 | MAX_TASK_NAME | (size_x + 1)); // TODO This realloc sucks. + size_t new_size = 2047 | MAX_TASK_NAME | (size_x + 1); + if (string_buffer_size < new_size) { + string_buffer_size = new_size; + string_buffer = realloc(string_buffer, string_buffer_size); + } update_layout(); layout = &layouts[size_x > 100 ? L_NORMAL : L_COMPACT]; break; @@ -1217,6 +1222,10 @@ int main(int argc, char *argv[]) { // Apply new task name. if (is_empty_string(string_buffer) == false) { + replace_char(string_buffer, '\t', ' '); + replace_char(string_buffer, '\v', ' '); + replace_char(string_buffer, '\f', ' '); + replace_char(string_buffer, '\r', ' '); memcpy(selected_task->name, string_buffer, MAX_TASK_NAME); } -- cgit v1.2.3