From 6c2101a44e367496e6a0d289aa24164adaae3d1d Mon Sep 17 00:00:00 2001 From: James Cook Date: Thu, 3 Dec 2009 09:32:05 -0800 Subject: EXT-2984 Fixed crash in LLNormalTextSegment::getDimensions (no repro) Avoid stepping off end of array when text segment has 0 characters Reviewed with Ambroff --- indra/llui/lltextbase.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'indra') diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index db16670f79..741ab1737d 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -2397,12 +2397,20 @@ void LLNormalTextSegment::setToolTip(const std::string& tooltip) bool LLNormalTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const { - LLWString text = mEditor.getWText(); - height = mFontHeight; - width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars); - // if last character is a newline, then return true, forcing line break - llwchar last_char = text[mStart + first_char + num_chars - 1]; + bool force_newline = false; + if (num_chars > 0) + { + LLWString text = mEditor.getWText(); + width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars); + // if last character is a newline, then return true, forcing line break + llwchar last_char = text[mStart + first_char + num_chars - 1]; + force_newline = (last_char == '\n'); + } + else + { + width = 0; + } LLUIImagePtr image = mStyle->getImage(); if( image.notNull()) @@ -2411,7 +2419,7 @@ bool LLNormalTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& widt height = llmax(height, image->getHeight()); } - return num_chars >= 1 && last_char == '\n'; + return force_newline; } S32 LLNormalTextSegment::getOffset(S32 segment_local_x_coord, S32 start_offset, S32 num_chars, bool round) const -- cgit v1.2.3