From: Anton Lindqvist Date: Wed, 20 Jul 2016 01:56:13 +0000 (-0700) Subject: Fix arithmetic exception due to menu->pagelen being negative. X-Git-Tag: neomutt-20160822~73 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e94eaaac32a77fdc82996e29ed164241ccfd124a;p=neomutt 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. --- diff --git a/curs_lib.c b/curs_lib.c index ed0d10c34..8b21c43fb 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;