Fix warning on CentOS 6 (refer to #282)

This commit is contained in:
Arun Prakash Jana 2019-06-13 06:07:53 +05:30
parent 444cf4b9ab
commit dba87bfdbe
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -1756,14 +1756,17 @@ static char *xreadline(char *prefill, char *prompt)
size_t len, pos; size_t len, pos;
int x, y, r; int x, y, r;
wint_t ch[2] = {0}; wint_t ch[2] = {0};
wchar_t * const buf = (wchar_t *)g_buf; wchar_t * const buf = malloc(sizeof(wchar_t) * CMD_LEN_MAX);
if (!buf)
errexit();
cleartimeout(); cleartimeout();
printprompt(prompt); printprompt(prompt);
if (prefill) { if (prefill) {
DPRINTF_S(prefill); DPRINTF_S(prefill);
len = pos = mbstowcs(buf, prefill, NAME_MAX); len = pos = mbstowcs(buf, prefill, CMD_LEN_MAX);
} else } else
len = (size_t)-1; len = (size_t)-1;
@ -1821,7 +1824,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 < NAME_MAX - 1) { if (pos < CMD_LEN_MAX - 1) {
memmove(buf + pos + 1, buf + pos, (len - pos) << 2); memmove(buf + pos + 1, buf + pos, (len - pos) << 2);
buf[pos] = *ch; buf[pos] = *ch;
++len, ++pos; ++len, ++pos;
@ -1869,8 +1872,9 @@ END:
clearprompt(); clearprompt();
buf[len] = '\0'; buf[len] = '\0';
wcstombs(g_buf + ((NAME_MAX + 1) << 2), buf, NAME_MAX); wcstombs(g_buf, buf, ++len);
return g_buf + ((NAME_MAX + 1) << 2); free(buf);
return g_buf;
} }
#ifndef NORL #ifndef NORL