Bug 1419362 part 1: Make IAccessibleHypertext2::hyperlinks return null and S_FALSE when there are no hyperlinks. r?MarcoZ draft
authorJames Teh <jteh@mozilla.com>
Wed, 22 Nov 2017 10:33:23 +1000
changeset 703074 e098330f9b5345db353ec6630ccdb315100ee71d
parent 702882 3f5d48c08903475b5f556f3d5906773978b30489
child 703075 1603b89a53d7089c8cbe009e5c306474becad266
push id90698
push userbmo:jteh@mozilla.com
push dateFri, 24 Nov 2017 09:13:42 +0000
reviewersMarcoZ
bugs1419362
milestone59.0a1
Bug 1419362 part 1: Make IAccessibleHypertext2::hyperlinks return null and S_FALSE when there are no hyperlinks. r?MarcoZ As per the spec, if there are no hyperlinks, the hyperlinks array should be set to null and S_FALSE should be returned. This saves pointless memory management when there are no hyperlinks. MozReview-Commit-ID: 9wsiXBely6G
accessible/windows/ia2/ia2AccessibleHypertext.cpp
--- a/accessible/windows/ia2/ia2AccessibleHypertext.cpp
+++ b/accessible/windows/ia2/ia2AccessibleHypertext.cpp
@@ -95,16 +95,21 @@ ia2AccessibleHypertext::get_hyperlinks(I
   HyperTextAccessibleWrap* hyperText = static_cast<HyperTextAccessibleWrap*>(this);
   if (hyperText->IsDefunct()) {
     return CO_E_OBJNOTCONNECTED;
   }
 
   uint32_t count = hyperText->LinkCount();
   *aNHyperlinks = count;
 
+  if (count == 0) {
+    *aHyperlinks = nullptr;
+    return S_FALSE;
+  }
+
   *aHyperlinks = static_cast<IAccessibleHyperlink**>(::CoTaskMemAlloc(
     sizeof(IAccessibleHyperlink*) * count));
   if (!*aHyperlinks) {
     return E_OUTOFMEMORY;
   }
 
   for (uint32_t i = 0; i < count; ++i) {
     AccessibleWrap* hyperLink =