From ce4bb9e16da1deb5ed1c95b57f313065bc06d623 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Thu, 12 May 2016 15:30:29 -0400 Subject: [PATCH] Fix potential NULL dereference in Paragraph.getWordBoundary. (#2679) Can happen when calling getWordBoundary on an empty Paragraph. --- sky/engine/core/text/Paragraph.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sky/engine/core/text/Paragraph.cpp b/sky/engine/core/text/Paragraph.cpp index 092189755c597..c3c144a3f0e53 100644 --- a/sky/engine/core/text/Paragraph.cpp +++ b/sky/engine/core/text/Paragraph.cpp @@ -157,7 +157,7 @@ Dart_Handle Paragraph::getPositionForOffset(const Offset& offset) { Dart_Handle Paragraph::getWordBoundary(unsigned offset) { String text; - int start, end; + int start = 0, end = 0; for (RenderObject* object = m_renderView.get(); object; object = object->nextInPreOrder()) { if (!object->isText()) @@ -167,10 +167,12 @@ Dart_Handle Paragraph::getWordBoundary(unsigned offset) { } TextBreakIterator* it = wordBreakIterator(text, 0, text.length()); - end = it->following(offset); - if (end < 0) - end = it->last(); - start = it->previous(); + if (it) { + end = it->following(offset); + if (end < 0) + end = it->last(); + start = it->previous(); + } Dart_Handle result = Dart_NewList(2); Dart_ListSetAt(result, 0, ToDart(start));