summaryrefslogtreecommitdiffstats
path: root/curs_lib.c
diff options
context:
space:
mode:
authorAnton Lindqvist <anton.lindqvist@gmail.com>2016-07-19 18:56:13 -0700
committerAnton Lindqvist <anton.lindqvist@gmail.com>2016-07-19 18:56:13 -0700
commit23095372e842fecf249990787174329ecbbe1693 (patch)
tree4565435095b70d2349ac5e23ff192400f6d6126b /curs_lib.c
parent848dbae248c88bebd028372394acc89616f7c247 (diff)
Fix arithmetic exception due to menu->pagelen being negative.
Resizing the terminal window down to two lines when in an empty mailbox causes mutt to crash due to division by zero since menu->max equals 0 and menu->pagelen < 0 in status.c:205. Fixing the problem at this specific line felt wrong since I did notice menu->pagelen being negative. The pagelen is inherited from the rows calculation in mutt_reflow_windows. Since the number of lines can potentially be smaller than the accumulated number of rows acquired by the status, help and message window, make sure the calculation does not turn negative.
Diffstat (limited to 'curs_lib.c')
-rw-r--r--curs_lib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/curs_lib.c b/curs_lib.c
index ed0d10c3..8b21c43f 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -531,8 +531,8 @@ void mutt_reflow_windows (void)
MuttMessageWindow->row_offset = LINES - 1;
memcpy (MuttIndexWindow, MuttStatusWindow, sizeof (mutt_window_t));
- MuttIndexWindow->rows = LINES - MuttStatusWindow->rows - MuttHelpWindow->rows -
- MuttMessageWindow->rows;
+ MuttIndexWindow->rows = MAX(LINES - MuttStatusWindow->rows -
+ MuttHelpWindow->rows - MuttMessageWindow->rows, 0);
MuttIndexWindow->row_offset = option (OPTSTATUSONTOP) ? MuttStatusWindow->rows :
MuttHelpWindow->rows;