summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorJames Cook <james@lindenlab.com>2009-12-03 09:32:05 -0800
committerJames Cook <james@lindenlab.com>2009-12-03 09:32:05 -0800
commit6c2101a44e367496e6a0d289aa24164adaae3d1d (patch)
treeba0d41ddd465dd7f3afaa5c58418a23d1636bb41 /indra
parentbbdfd84e2a7e3482143260acf75adb8968fa71bb (diff)
EXT-2984 Fixed crash in LLNormalTextSegment::getDimensions (no repro)
Avoid stepping off end of array when text segment has 0 characters Reviewed with Ambroff
Diffstat (limited to 'indra')
-rw-r--r--indra/llui/lltextbase.cpp20
1 files changed, 14 insertions, 6 deletions
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