Skip to content

Commit

Permalink
Fix potential NULL dereference in Paragraph.getWordBoundary. (flutter…
Browse files Browse the repository at this point in the history
…#2679)

Can happen when calling getWordBoundary on an empty Paragraph.
  • Loading branch information
mpcomplete committed May 12, 2016
1 parent 57edc53 commit ce4bb9e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions sky/engine/core/text/Paragraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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));
Expand Down

0 comments on commit ce4bb9e

Please sign in to comment.