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.

git-svn-id: svn://10.0.0.236/trunk@179341 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bryner%brianryner.com
2005-08-30 20:56:49 +00:00
parent d3e53a63c2
commit 29d1177089

View File

@@ -7709,21 +7709,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<nsISHEntry> destEntry;
nsCOMPtr<nsISHContainer> 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<nsISHEntry> 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;
}