Perform a bounds check to fix a random Termcurses crash that I haven't been able to track down. The result of of the subtraction for priv->keycount should never be negative, but I think sometimes it is, so better to catch it and avoid a crash until I can track it down.

This commit is contained in:
Ken Pettit ‎ 2019-01-16 18:22:16 -06:00 committed by Gregory Nutt
parent 93de0c232b
commit b285dd9b68
2 changed files with 9 additions and 0 deletions

View File

@ -12,6 +12,8 @@ config SYSTEM_TERMCURSES
Terminal emulation library for curses support on TTY type consoles Terminal emulation library for curses support on TTY type consoles
such as serial port, CDCACM, telnet, etc. such as serial port, CDCACM, telnet, etc.
Must deselect CONFIG_DISABLE_POLL!
config SYSTEM_TERMCURSES_VT100 config SYSTEM_TERMCURSES_VT100
bool "Terminal pdcurses support for VT-100" bool "Terminal pdcurses support for VT-100"
depends on SYSTEM_TERMCURSES depends on SYSTEM_TERMCURSES

View File

@ -1041,6 +1041,13 @@ static int tcurses_vt100_getkeycode(FAR struct termcurses_s *dev, FAR int *speci
/* Update keycount and keybuf */ /* Update keycount and keybuf */
priv->keycount -= x; priv->keycount -= x;
if (priv->keycount < 0)
{
/* Hmm, some bug. Better to simply ignore than to crash */
priv->keycount = 0;
}
if (priv->keycount != 0) if (priv->keycount != 0)
{ {
memmove(priv->keybuf, &priv->keybuf[x], priv->keycount); memmove(priv->keybuf, &priv->keybuf[x], priv->keycount);