diff options
author | Mathias Gumz <akira@fluxbox.org> | 2022-05-28 09:13:43 (GMT) |
---|---|---|
committer | Mathias Gumz <mgumz@users.noreply.github.com> | 2022-07-31 14:49:49 (GMT) |
commit | 9d8202f32338a3f08d3fa39057dc5eec5d97be4e (patch) | |
tree | 85238fab1759c2b826affe6826ab00e81dd5a6ba | |
parent | e2cbd179ecb2ef2d76e0ad1fde84b44325305799 (diff) | |
download | fluxbox-9d8202f32338a3f08d3fa39057dc5eec5d97be4e.zip fluxbox-9d8202f32338a3f08d3fa39057dc5eec5d97be4e.tar.bz2 |
Fix infinite loop in Menu::cycleitems()
When a menu contains no selectable item (example given: a "list" of user
styles and the only available one is already selected), cycling through
the menu will lead to an infinite loop and thus a disfunctional fluxbox.
This commit addresses the issue by checking if there is any selectable
item before entering the cycling stage.
Discovered by Sébastien Ballet[1].
[1]: https://sourceforge.net/p/fluxbox/bugs/1185/
-rw-r--r-- | src/FbTk/Menu.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 6b2db3a..ff040ba 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc | |||
@@ -320,15 +320,24 @@ void Menu::lower() { | |||
320 | 320 | ||
321 | void Menu::cycleItems(bool reverse) { | 321 | void Menu::cycleItems(bool reverse) { |
322 | 322 | ||
323 | if (m_items.empty()) | ||
324 | return; | ||
325 | |||
326 | int offset = reverse ? -1 : 1; | ||
327 | int l = m_items.size(); | 323 | int l = m_items.size(); |
328 | int i = m_active_index; | 324 | int i; |
325 | int offset = reverse ? -1 : 1; | ||
329 | size_t ignore; | 326 | size_t ignore; |
330 | 327 | ||
331 | for (i += offset; i != m_active_index; i += offset ) { | 328 | // check if there is _any_ selectable item |
329 | for (i = 0; i < l; i++) { | ||
330 | if (isItemSelectable(i)) { | ||
331 | break; | ||
332 | } | ||
333 | } | ||
334 | |||
335 | // no selectable item | ||
336 | if (i >= l) { | ||
337 | return; | ||
338 | } | ||
339 | |||
340 | for (i = m_active_index + offset; i != m_active_index; i += offset ) { | ||
332 | if (i < 0) { | 341 | if (i < 0) { |
333 | i = l - 1; | 342 | i = l - 1; |
334 | } else if (i >= l) { | 343 | } else if (i >= l) { |