mirror of
https://github.com/jarun/nnn.git
synced 2024-11-20 01:49:14 +00:00
Limit imput length at readline prompt
This commit is contained in:
parent
2f4144b0bd
commit
baac461b33
13
src/nnn.c
13
src/nnn.c
|
@ -117,6 +117,7 @@
|
||||||
#define TOUPPER(ch) \
|
#define TOUPPER(ch) \
|
||||||
(((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
|
(((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
|
||||||
#define CMD_LEN_MAX (PATH_MAX + ((NAME_MAX + 1) << 1))
|
#define CMD_LEN_MAX (PATH_MAX + ((NAME_MAX + 1) << 1))
|
||||||
|
#define READLINE_MAX 128
|
||||||
#define FILTER '/'
|
#define FILTER '/'
|
||||||
#define MSGWAIT '$'
|
#define MSGWAIT '$'
|
||||||
#define REGEX_MAX 48
|
#define REGEX_MAX 48
|
||||||
|
@ -1818,7 +1819,7 @@ static char *xreadline(char *prefill, char *prompt)
|
||||||
int x, r;
|
int x, r;
|
||||||
const int WCHAR_T_WIDTH = sizeof(wchar_t);
|
const int WCHAR_T_WIDTH = sizeof(wchar_t);
|
||||||
wint_t ch[2] = {0};
|
wint_t ch[2] = {0};
|
||||||
wchar_t * const buf = malloc(sizeof(wchar_t) * CMD_LEN_MAX);
|
wchar_t * const buf = malloc(sizeof(wchar_t) * READLINE_MAX);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
errexit();
|
errexit();
|
||||||
|
@ -1828,7 +1829,7 @@ static char *xreadline(char *prefill, char *prompt)
|
||||||
|
|
||||||
if (prefill) {
|
if (prefill) {
|
||||||
DPRINTF_S(prefill);
|
DPRINTF_S(prefill);
|
||||||
len = pos = mbstowcs(buf, prefill, CMD_LEN_MAX);
|
len = pos = mbstowcs(buf, prefill, READLINE_MAX);
|
||||||
} else
|
} else
|
||||||
len = (size_t)-1;
|
len = (size_t)-1;
|
||||||
|
|
||||||
|
@ -1887,7 +1888,7 @@ static char *xreadline(char *prefill, char *prompt)
|
||||||
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^')
|
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pos < CMD_LEN_MAX - 1) {
|
if (pos < READLINE_MAX - 1) {
|
||||||
memmove(buf + pos + 1, buf + pos,
|
memmove(buf + pos + 1, buf + pos,
|
||||||
(len - pos) * WCHAR_T_WIDTH);
|
(len - pos) * WCHAR_T_WIDTH);
|
||||||
buf[pos] = *ch;
|
buf[pos] = *ch;
|
||||||
|
@ -1945,9 +1946,9 @@ END:
|
||||||
|
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
pos = wcstombs(g_buf, buf, CMD_LEN_MAX - 1);
|
pos = wcstombs(g_buf, buf, READLINE_MAX - 1);
|
||||||
if (pos >= CMD_LEN_MAX - 1)
|
if (pos >= READLINE_MAX - 1)
|
||||||
g_buf[CMD_LEN_MAX - 1] = '\0';
|
g_buf[READLINE_MAX - 1] = '\0';
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return g_buf;
|
return g_buf;
|
||||||
|
|
Loading…
Reference in a new issue