Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: Source/core/editing/ApplyStyleCommand.cpp

Issue 177093016: Fix crash in ApplyStyleCommand::applyRelativeFontStyleChange() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reduce layout test Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/editing/style/apply-style-crash2-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/ApplyStyleCommand.cpp
diff --git a/Source/core/editing/ApplyStyleCommand.cpp b/Source/core/editing/ApplyStyleCommand.cpp
index 9cce975b80f19764e88e76b93ffd148f5dc38ce2..d809696167311c30dd9454cb1e7c5325a58bf18d 100644
--- a/Source/core/editing/ApplyStyleCommand.cpp
+++ b/Source/core/editing/ApplyStyleCommand.cpp
@@ -349,7 +349,9 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
// Calculate loop end point.
// If the end node is before the start node (can only happen if the end node is
// an ancestor of the start node), we gather nodes up to the next sibling of the end node
- Node *beyondEnd;
+ Node* beyondEnd;
+ ASSERT(start.deprecatedNode());
+ ASSERT(end.deprecatedNode());
if (start.deprecatedNode()->isDescendantOf(end.deprecatedNode()))
beyondEnd = NodeTraversal::nextSkippingChildren(*end.deprecatedNode());
else
@@ -358,20 +360,29 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
start = start.upstream(); // Move upstream to ensure we do not add redundant spans.
Node* startNode = start.deprecatedNode();
ASSERT(startNode);
+
+ // Make sure we're not already at the end or the next NodeTraversal::next() will traverse
+ // past it.
+ if (startNode == beyondEnd)
+ return;
+
if (startNode->isTextNode() && start.deprecatedEditingOffset() >= caretMaxOffset(startNode)) // Move out of text node if range does not include its characters.
startNode = NodeTraversal::next(*startNode);
// Store away font size before making any changes to the document.
// This ensures that changes to one node won't effect another.
HashMap<Node*, float> startingFontSizes;
- for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node))
+ for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
+ ASSERT(node);
startingFontSizes.set(node, computedFontSize(node));
+ }
// These spans were added by us. If empty after font size changes, they can be removed.
Vector<RefPtr<HTMLElement> > unstyledSpans;
Node* lastStyledNode = 0;
for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
+ ASSERT(node);
RefPtr<HTMLElement> element;
if (node->isHTMLElement()) {
// Only work on fully selected nodes.
« no previous file with comments | « LayoutTests/editing/style/apply-style-crash2-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698