diff options
| author | dam <dam@gudinoff> | 2022-10-23 23:37:01 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-10-23 23:37:01 +0000 |
| commit | f62a1e1b2c9358997da9f12edffaf2120f56f3ed (patch) | |
| tree | 91455b39869d38ac1706ec043c184f632335ac4a | |
| parent | 3a590dd7c156b1bdf4a119921ee39035b2ec1626 (diff) | |
| download | task-time-tracker-f62a1e1b2c9358997da9f12edffaf2120f56f3ed.tar.zst task-time-tracker-f62a1e1b2c9358997da9f12edffaf2120f56f3ed.zip | |
Improved string_buffer allocation. Sanitize task names on input.
| -rw-r--r-- | main.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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); } |
