diff options
| author | Louis Burda <quent.burda@gmail.com> | 2022-01-29 01:01:17 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2022-02-13 17:02:44 +0100 |
| commit | f5ccba488250d09df9c4a0d5f50a1e7666e7cac3 (patch) | |
| tree | 422898eef3a5408aa44fc4c714e103d146cf5084 /src/history.c | |
| parent | b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d (diff) | |
| download | tmus-f5ccba488250d09df9c4a0d5f50a1e7666e7cac3.tar.gz tmus-f5ccba488250d09df9c4a0d5f50a1e7666e7cac3.zip | |
Fix inputln uninitialized, missing counter
Diffstat (limited to 'src/history.c')
| -rw-r--r-- | src/history.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/history.c b/src/history.c index a0ede46..5bdac39 100644 --- a/src/history.c +++ b/src/history.c @@ -112,6 +112,7 @@ inputln_init(struct inputln *ln) ln->cap = 0; ln->cur = 0; ln->link = LINK_EMPTY; + inputln_resize(ln, 128); } struct inputln * @@ -122,7 +123,6 @@ inputln_alloc(void) ln = malloc(sizeof(struct inputln)); ASSERT(ln != NULL); inputln_init(ln); - inputln_resize(ln, 128); return ln; } @@ -202,11 +202,10 @@ inputln_copy(struct inputln *dst, struct inputln *src) void inputln_replace(struct inputln *line, const wchar_t *str) { - free(line->buf); - line->buf = wcsdup(str); - ASSERT(line->buf != NULL); line->len = wcslen(str); - line->cap = line->len + 1; + if (line->cap <= line->len) + inputln_resize(line, line->len + 1); + line->buf = wcscpy(line->buf, str); line->cur = line->len; } |
