* 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:
Stefan Schimanski 2008-02-26 13:46:54 +00:00
parent 924ed25c61
commit 83ae753214

View File

@ -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