1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

switch_to_tab: Prevent "tab number out of range" assertion failure.

To reproduce:
- Start ELinks.
- Enable the ui.tabs.wraparound option.
- Press t to open a second tab.
- Go to http://elinks.cz/ in the second tab.
- Press 3< to step three tabs to the left.

In the statement "tab = tabs + tab % tabs;", tab == -2 and tabs == 2.
So tab % tabs == 0 and tab becomes 2, which is out of range.

The new version calls get_opt_bool even if the tab parameter is already in
range, but the cost should be negligible compared to the redraw_terminal()
call that follows.
This commit is contained in:
Kalle Olavi Niemitalo 2006-09-27 21:29:27 +03:00 committed by Kalle Olavi Niemitalo
parent 86bc6a534b
commit bac6e76c23

View File

@ -138,19 +138,11 @@ switch_to_tab(struct terminal *term, int tab, int tabs)
if (tabs < 0) tabs = number_of_tabs(term);
if (tabs > 1) {
if (tab >= tabs) {
if (get_opt_bool("ui.tabs.wraparound"))
tab = tab % tabs;
else
tab = tabs - 1;
}
if (tab < 0) {
if (get_opt_bool("ui.tabs.wraparound"))
tab = tabs + tab % tabs;
else
tab = 0;
}
if (get_opt_bool("ui.tabs.wraparound")) {
tab %= tabs;
if (tab < 0) tab += tabs;
} else
int_bounds(&tab, 0, tabs - 1);
} else tab = 0;
if (tab != term->current_tab) {