Bug 1427635: Fix DoCompareTreePosition frame tree version with null aCommonAncestor. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 22 Dec 2017 11:01:19 +0100
changeset 715179 16260ea5ce052ccfd5b015adecc32b2f3812db47
parent 715175 99f906c40d7fd9391e9e3b0994437fe162027710
child 744722 635157b8a6deacbe0e493f97d880ede61828b4a5
push id94081
push userbmo:emilio@crisal.io
push dateTue, 02 Jan 2018 23:54:28 +0000
reviewersxidorn
bugs1427635
milestone59.0a1
Bug 1427635: Fix DoCompareTreePosition frame tree version with null aCommonAncestor. r?xidorn It doesn't fill the ancestors of the first frame if aCommonAncestor is null, which means that we get garbage afterwards. MozReview-Commit-ID: G85dv7KM1Xd
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1908,18 +1908,21 @@ nsLayoutUtils::DoCompareTreePosition(nsI
 
   nsPresContext* presContext = aFrame1->PresContext();
   if (presContext != aFrame2->PresContext()) {
     NS_ERROR("no common ancestor at all, different documents");
     return 0;
   }
 
   AutoTArray<nsIFrame*,20> frame1Ancestors;
-  if (aCommonAncestor &&
-      !FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors)) {
+  // Note that the order of the condition is important. We need to fill the
+  // ancestors even if aCommonAncestor is null, otherwise the code below makes
+  // no sense.
+  if (!FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors) &&
+      aCommonAncestor) {
     // We reached the root of the frame tree ... if aCommonAncestor was set,
     // it is wrong
     return DoCompareTreePosition(aFrame1, aFrame2,
                                  aIf1Ancestor, aIf2Ancestor, nullptr);
   }
 
   int32_t last1 = int32_t(frame1Ancestors.Length()) - 1;
   int32_t last2 = int32_t(aFrame2Ancestors.Length()) - 1;