From b2dffbabb64a045ab01907bbbb9e621787201efe Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 16 May 2013 21:44:58 +0200 Subject: [PATCH] more robust NCursesUI::menu_show --- src/ncurses.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ncurses.cc b/src/ncurses.cc index f4e44d90..54600c09 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -420,12 +420,15 @@ void NCursesUI::menu_show(const memoryview& choices, DisplayCoord maxsize = window_size(stdscr); maxsize.column -= anchor.column; + if (maxsize.column <= 2) + return; m_choices.reserve(choices.size()); CharCount longest = 0; + const CharCount maxlen = std::min((int)maxsize.column-2, 200); for (auto& choice : choices) { - m_choices.push_back(choice.substr(0_char, std::min((int)maxsize.column-2, 200))); + m_choices.push_back(choice.substr(0_char, maxlen)); longest = std::max(longest, m_choices.back().char_length()); } longest += 1;