Bug 1622731 - Make nsCoreUtils tree/column functions null-safe. r=Jamie
authorEitan Isaacson <eitan@monotonous.org>
Tue, 24 Mar 2020 19:07:30 +0000
changeset 520263 6aa798ae8615af885ebe9efc461db4d5b26f6d9f
parent 520262 24568b324c27ede4a89278ee7875b4db891e03d7
child 520264 be2533473311e2fc79d5917998d419c9cc479543
push id37246
push useropoprus@mozilla.com
push dateWed, 25 Mar 2020 03:40:33 +0000
treeherdermozilla-central@14b59d4adc95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1622731
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1622731 - Make nsCoreUtils tree/column functions null-safe. r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D67673
accessible/base/nsCoreUtils.cpp
--- a/accessible/base/nsCoreUtils.cpp
+++ b/accessible/base/nsCoreUtils.cpp
@@ -431,80 +431,107 @@ XULTreeElement* nsCoreUtils::GetTree(nsI
     currentContent = currentContent->GetFlattenedTreeParent();
   }
 
   return nullptr;
 }
 
 already_AddRefed<nsTreeColumn> nsCoreUtils::GetFirstSensibleColumn(
     XULTreeElement* aTree) {
+  if (!aTree) {
+    return nullptr;
+  }
+
   RefPtr<nsTreeColumns> cols = aTree->GetColumns();
-  if (!cols) return nullptr;
+  if (!cols) {
+    return nullptr;
+  }
 
   RefPtr<nsTreeColumn> column = cols->GetFirstColumn();
   if (column && IsColumnHidden(column)) return GetNextSensibleColumn(column);
 
   return column.forget();
 }
 
 uint32_t nsCoreUtils::GetSensibleColumnCount(XULTreeElement* aTree) {
   uint32_t count = 0;
+  if (!aTree) {
+    return count;
+  }
 
   RefPtr<nsTreeColumns> cols = aTree->GetColumns();
-  if (!cols) return count;
+  if (!cols) {
+    return count;
+  }
 
   nsTreeColumn* column = cols->GetFirstColumn();
 
   while (column) {
     if (!IsColumnHidden(column)) count++;
 
     column = column->GetNext();
   }
 
   return count;
 }
 
 already_AddRefed<nsTreeColumn> nsCoreUtils::GetSensibleColumnAt(
     XULTreeElement* aTree, uint32_t aIndex) {
+  if (!aTree) {
+    return nullptr;
+  }
+
   uint32_t idx = aIndex;
 
   nsCOMPtr<nsTreeColumn> column = GetFirstSensibleColumn(aTree);
   while (column) {
     if (idx == 0) return column.forget();
 
     idx--;
     column = GetNextSensibleColumn(column);
   }
 
   return nullptr;
 }
 
 already_AddRefed<nsTreeColumn> nsCoreUtils::GetNextSensibleColumn(
     nsTreeColumn* aColumn) {
+  if (!aColumn) {
+    return nullptr;
+  }
+
   RefPtr<nsTreeColumn> nextColumn = aColumn->GetNext();
 
   while (nextColumn && IsColumnHidden(nextColumn)) {
     nextColumn = nextColumn->GetNext();
   }
 
   return nextColumn.forget();
 }
 
 already_AddRefed<nsTreeColumn> nsCoreUtils::GetPreviousSensibleColumn(
     nsTreeColumn* aColumn) {
+  if (!aColumn) {
+    return nullptr;
+  }
+
   RefPtr<nsTreeColumn> prevColumn = aColumn->GetPrevious();
 
   while (prevColumn && IsColumnHidden(prevColumn)) {
     prevColumn = prevColumn->GetPrevious();
   }
 
   return prevColumn.forget();
 }
 
 bool nsCoreUtils::IsColumnHidden(nsTreeColumn* aColumn) {
+  if (!aColumn) {
+    return false;
+  }
+
   Element* element = aColumn->Element();
   return element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
                               nsGkAtoms::_true, eCaseMatters);
 }
 
 void nsCoreUtils::ScrollTo(PresShell* aPresShell, nsIContent* aContent,
                            uint32_t aScrollType) {
   ScrollAxis vertical, horizontal;