Fix SIGFPE regression in tty_info() introduced in rl_reset_terminal() commit.

When adding support for rl_reset_termial() the tty_info() code was also
refactored.  This however led to the introduction of a bug that caused
tty_cols to be set to zero.  This in turn caused c_possible() to fail
with SIGFPE in el_print_columns().

Regression was introduced in 1c89c9886c
This commit is contained in:
Joachim Nilsson 2010-08-12 16:20:29 +02:00
parent d72069144e
commit 850e36f9db

View File

@ -244,23 +244,6 @@ static void tty_backn(int n)
static void tty_info(void) static void tty_info(void)
{ {
static int init;
if (init) {
#ifdef TIOCGWINSZ
struct winsize W;
if (ioctl(el_outfd, TIOCGWINSZ, &W) >= 0 && W.ws_col > 0 && W.ws_row > 0) {
tty_cols = (int)W.ws_col;
tty_rows = (int)W.ws_row;
}
#endif
return;
}
init++;
/* Initialize to faulty values to trigger fallback if nothing else works. */
tty_cols = tty_rows = -1;
rl_reset_terminal(NULL); rl_reset_terminal(NULL);
} }
@ -1091,11 +1074,12 @@ void rl_reset_terminal(const char *terminal_name)
if (terminal_name) { if (terminal_name) {
el_term = terminal_name; el_term = terminal_name;
return; } else if ((el_term = getenv("TERM")) == NULL) {
el_term = "dumb";
} }
if ((el_term = getenv("TERM")) == NULL) /* Initialize to faulty values to trigger fallback if nothing else works. */
el_term = "dumb"; tty_cols = tty_rows = -1;
#ifdef CONFIG_USE_TERMCAP #ifdef CONFIG_USE_TERMCAP
bp = buff; bp = buff;
@ -1110,7 +1094,7 @@ void rl_reset_terminal(const char *terminal_name)
if (tty_cols <= 0 || tty_rows <= 0) { if (tty_cols <= 0 || tty_rows <= 0) {
#ifdef TIOCGWINSZ #ifdef TIOCGWINSZ
if (-1 != ioctl(el_outfd, TIOCGWINSZ, &W)) { if (ioctl(el_outfd, TIOCGWINSZ, &W) >= 0 && W.ws_col > 0 && W.ws_row > 0) {
tty_cols = (int)W.ws_col; tty_cols = (int)W.ws_col;
tty_rows = (int)W.ws_row; tty_rows = (int)W.ws_row;
return; return;