commit 7fe520fd8f7efd4b75551b6bb0ad099ae138d686
parent 8bce901714e47fda0cf553a4b597ad4c182b63aa
Author: hhvn <dev@hhvn.uk>
Date: Wed, 22 Jun 2022 19:41:14 +0100
Use fixed size array for ui.arg
Diffstat:
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/zygo.c b/zygo.c
@@ -49,7 +49,7 @@ struct {
* 2 - yes (id) */
wchar_t input[BUFLEN];
char cmd;
- char *arg;
+ char arg[BUFLEN * 4]; /* UTF8 max char size: 4 bytes. 4x sizeof(input) */
int search;
regex_t regex;
int error;
@@ -810,20 +810,18 @@ input(int c) {
if (!c) {
ui.input[il = 0] = '\0';
- free(ui.arg);
- ui.arg = estrdup("");
+ ui.arg[0] = '\0';
return;
} else if (c == KEY_BACKSPACE) {
ui.input[--il] = '\0';
+ } else if (il == sizeof(ui.input)) {
+ return;
} else {
ui.input[il++] = c;
ui.input[il] = '\0';
}
- free(ui.arg);
- len = wcstombs(NULL, ui.input, 0) + 1;
- ui.arg = emalloc(len);
- wcstombs(ui.arg, ui.input, len);
+ wcstombs(ui.arg, ui.input, sizeof(ui.arg));
}
char *