mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 05:33:33 +00:00
* undeflow fix for i == -1
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23249 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
924ed25c61
commit
83ae753214
@ -613,10 +613,10 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In sorted models, do binary search for s.
|
// In sorted models, do binary search for s.
|
||||||
i = 0;
|
int l = 0;
|
||||||
size_t r = n - 1;
|
int r = n - 1;
|
||||||
while (r >= i && i < n) {
|
while (r >= l && l < int(n)) {
|
||||||
size_t mid = (r + i) / 2;
|
size_t mid = (r + l) / 2;
|
||||||
QString const & mids
|
QString const & mids
|
||||||
= model.data(model.index(mid, 0),
|
= model.data(model.index(mid, 0),
|
||||||
Qt::EditRole).toString();
|
Qt::EditRole).toString();
|
||||||
@ -626,22 +626,25 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
|
|||||||
// from the CompletionList has?
|
// from the CompletionList has?
|
||||||
int c = s.compare(mids, Qt::CaseSensitive);
|
int c = s.compare(mids, Qt::CaseSensitive);
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
i = mid;
|
l = mid;
|
||||||
break;
|
break;
|
||||||
} else if (i == r) {
|
} else if (l == r) {
|
||||||
i = n;
|
l = n;
|
||||||
break;
|
break;
|
||||||
} else if (c > 0)
|
} else if (c > 0)
|
||||||
// middle is not far enough
|
// middle is not far enough
|
||||||
i = mid + 1;
|
l = mid + 1;
|
||||||
else
|
else
|
||||||
// middle is too far
|
// middle is too far
|
||||||
r = mid - 1;
|
r = mid - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop was left without finding anything
|
// loop was left without finding anything
|
||||||
if (r < i)
|
if (r < l)
|
||||||
i = n;
|
i = n;
|
||||||
|
else
|
||||||
|
i = l;
|
||||||
|
BOOST_ASSERT(0 <= i && i <= n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// select the first if none was found
|
// select the first if none was found
|
||||||
|
Loading…
Reference in New Issue
Block a user