commit f5ccba488250d09df9c4a0d5f50a1e7666e7cac3
parent b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d
Author: Louis Burda <quent.burda@gmail.com>
Date: Sat, 29 Jan 2022 01:01:17 +0100
Fix inputln uninitialized, missing counter
Diffstat:
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git 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;
}
diff --git a/src/main.c b/src/main.c
@@ -847,8 +847,9 @@ select_tag(const wchar_t *query)
struct link *iter;
int index;
- index = 0;
+ index = -1;
for (LIST_ITER(&tags, iter)) {
+ index += 1;
tag = UPCAST(iter, struct tag);
if (wcsstr(tag->name, query)) {
listnav_update_sel(&tag_nav, index);