Make sure we don't end up with a too-negative mIndex. Bug 218639, r=timeless, sr=jag

This commit is contained in:
bzbarsky%mit.edu 2005-08-18 11:16:51 +00:00
Родитель 0aa846f258
Коммит 168b5e0b75
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -358,7 +358,9 @@ nsSHistory::PurgeHistory(PRInt32 aEntries)
{
if (mLength <= 0 || aEntries <= 0)
return NS_ERROR_FAILURE;
aEntries = PR_MIN(aEntries, mLength);
PRBool purgeHistory = PR_TRUE;
// Notify the listener about the history purge
if (mListener) {
@ -375,16 +377,20 @@ nsSHistory::PurgeHistory(PRInt32 aEntries)
PRInt32 cnt = 0;
while (cnt < aEntries) {
nsCOMPtr<nsISHTransaction> txn = mListRoot;
nsCOMPtr<nsISHTransaction> nextTxn;
if (mListRoot)
mListRoot->GetNext(getter_AddRefs(nextTxn));
txn = nsnull;
mListRoot = nextTxn;
cnt++;
}
mLength -= cnt;
mIndex -= cnt;
// Now if we were not at the end of the history, mIndex could have
// become far too negative. If so, just set it to -1.
if (mIndex < -1) {
mIndex = -1;
}
return NS_OK;
}