Fix off-by-one in menu logic

If a menu was all text except for the last element, the menu would
incorrectly be classifed as all text, and citem would be pinned to the
first element.

Fixes: 14a9657136 ("Use partial_range to store newmenu_item pointer/length")
This commit is contained in:
Kp 2020-10-03 22:34:38 +00:00
parent c482d01be5
commit 56b45ca2e8

View file

@ -1447,9 +1447,9 @@ static void newmenu_create_structure( newmenu *menu )
if (menu->citem != -1)
{
if (menu->citem < 0 ) menu->citem = 0;
const std::size_t nitems = menu->items.size() - 1;
if (menu->citem > nitems)
menu->citem = nitems;
const std::size_t nitems = menu->items.size();
if (menu->citem > nitems - 1)
menu->citem = nitems - 1;
menu->dblclick_flag = 1;
uint_fast32_t i = 0;