diff options
author | pommicket <pommicket@gmail.com> | 2022-12-20 12:28:14 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-20 12:28:14 -0500 |
commit | 6b88ac48b9731771f85df727754a3bab998d7d2b (patch) | |
tree | 718bd54bbb7f04127868a564e55ac95a7fe37f04 /buffer.c | |
parent | caf81c5a2c8b9432792c652edd0dcf1f64f7a4f1 (diff) | |
parent | 927f3eba4140be1526d51af9ecfc88b72b57dee2 (diff) |
Merge branch 'trunk' into lsp
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -1394,7 +1394,8 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32 // create a copy of str. we need to do this to remove carriage returns and newlines in the case of line buffers char32_t str_copy[256]; - if (str.len > arr_count(str_copy)) { + bool str_is_allocated = str.len > arr_count(str_copy); + if (str_is_allocated) { char32_t *new_str = buffer_calloc(buffer, str.len, sizeof *new_str); memcpy(new_str, str.str, str.len * sizeof *str.str); str.str = new_str; @@ -1494,9 +1495,8 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32 buffer_lines_modified(buffer, pos.line, line_idx); BufferPos b = {.line = line_idx, .index = index}; - if (str.len > arr_count(str_copy)) { + if (str_is_allocated) free(str.str); - } return b; } |