Bug 1317704 - Part 1. Hold current ranges into RemoveInlineProperty. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 15 Dec 2016 15:01:53 +0900
changeset 449824 f38ca4a9e53ab043326d35f214a268ff36fd55d8
parent 449801 7652a58efa46f1c57c94bba26efc5d53b6184e83
child 449825 6057059c0e33ec572ef0bad73c5fdb81ba83a8e0
push id38683
push userm_kato@ga2.so-net.ne.jp
push dateThu, 15 Dec 2016 06:07:26 +0000
reviewersmasayuki
bugs1317704
milestone53.0a1
Bug 1317704 - Part 1. Hold current ranges into RemoveInlineProperty. r?masayuki Since current selection ranges might be modified by SplitStyleAboveRange, this crash occurs into RemoveInlinePropertyImpl. So we need hold current selection range for loop. MozReview-Commit-ID: JuXn9XlwCp6
editor/libeditor/HTMLStyleEditor.cpp
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -1226,18 +1226,23 @@ HTMLEditor::RemoveInlinePropertyImpl(nsI
   TextRulesInfo ruleInfo(EditAction::removeTextProperty);
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
   nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     uint32_t rangeCount = selection->RangeCount();
+    // Since ranges might be modified by SplitStyleAboveRange, we need hold
+    // current ranges
+    AutoTArray<OwningNonNull<nsRange>, 8> arrayOfRanges;
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
-      OwningNonNull<nsRange> range = *selection->GetRangeAt(rangeIdx);
+      arrayOfRanges.AppendElement(*selection->GetRangeAt(rangeIdx));
+    }
+    for (auto& range : arrayOfRanges) {
       if (aProperty == nsGkAtoms::name) {
         // Promote range if it starts or end in a named anchor and we want to
         // remove named anchors
         rv = PromoteRangeIfStartsOrEndsInNamedAnchor(range);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       } else {