From 850e36f9db48a54ab84b4d11095a7e7f2b0f6e01 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 12 Aug 2010 16:20:29 +0200 Subject: [PATCH] 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 1c89c9886c68d2e5e98bbbe5e4385c90c18593d4 --- src/editline.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/editline.c b/src/editline.c index a4f004a..caa7378 100644 --- a/src/editline.c +++ b/src/editline.c @@ -244,23 +244,6 @@ static void tty_backn(int n) 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); } @@ -1091,11 +1074,12 @@ void rl_reset_terminal(const char *terminal_name) if (terminal_name) { el_term = terminal_name; - return; + } else if ((el_term = getenv("TERM")) == NULL) { + el_term = "dumb"; } - if ((el_term = getenv("TERM")) == NULL) - el_term = "dumb"; + /* Initialize to faulty values to trigger fallback if nothing else works. */ + tty_cols = tty_rows = -1; #ifdef CONFIG_USE_TERMCAP bp = buff; @@ -1110,7 +1094,7 @@ void rl_reset_terminal(const char *terminal_name) if (tty_cols <= 0 || tty_rows <= 0) { #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_rows = (int)W.ws_row; return;