From 0d0cae494eaef6f3580870fd4331b19d0b50d1ca Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Wed, 31 Aug 2005 19:05:41 +0000 Subject: [PATCH] Walk the list of SHEntry children looking for the target id if it's not at the expected index, and don't crash if there isn't one. Bug 305531, r+sr=bzbarsky, a=cbeard. git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@179410 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 36 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index c700e6c4d6a..49450b18946 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -7710,21 +7710,39 @@ nsDocShell::SetChildHistoryEntry(nsISHEntry *aEntry, nsDocShell *aShell, nsISHEntry *destTreeRoot = data->destTreeRoot; - // aEntry is a clone of the child of destTreeParent with the same index. nsCOMPtr destEntry; nsCOMPtr container = do_QueryInterface(data->destTreeParent); if (container) { - container->GetChildAt(aEntryIndex, getter_AddRefs(destEntry)); - NS_ASSERTION(destEntry, "oops, history trees are out of sync"); + // aEntry is a clone of some child of destTreeParent, but since the + // trees aren't necessarily in sync, we'll have to locate it. + // Note that we could set aShell's entry to null if we don't find a + // corresponding entry under destTreeParent. -#ifdef DEBUG - PRUint32 id1, id2; - aEntry->GetID(&id1); - destEntry->GetID(&id2); - NS_ASSERTION(id1 == id2, "oops, history trees are out of sync"); -#endif + PRUint32 targetID, id; + aEntry->GetID(&targetID); + + // First look at the given index, since this is the common case. + nsCOMPtr entry; + container->GetChildAt(aEntryIndex, getter_AddRefs(entry)); + if (entry && NS_SUCCEEDED(entry->GetID(&id)) && id == targetID) { + destEntry.swap(entry); + } else { + PRInt32 childCount; + container->GetChildCount(&childCount); + for (PRInt32 i = 0; i < childCount; ++i) { + container->GetChildAt(i, getter_AddRefs(entry)); + if (!entry) + continue; + + entry->GetID(&id); + if (id == targetID) { + destEntry.swap(entry); + break; + } + } + } } else { destEntry = destTreeRoot; }