From 73318bbc6a48be00aa4d3f73cdfdba6875616f6d Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Wed, 20 Mar 2024 22:06:59 +0200
Subject: viewer#1018 Crash at insertStringNoUndo

getEditableIndex retuns pos as is if only one segment is present
---
 indra/llui/lltextbase.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'indra')

diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 61b67e346e..bb3ce49b8b 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -845,7 +845,14 @@ S32 LLTextBase::insertStringNoUndo(S32 pos, const LLWString &wstr, LLTextBase::s
 	S32 old_len = getLength();		// length() returns character length
 	S32 insert_len = wstr.length();
 
-	pos = getEditableIndex(pos, true);
+    pos = getEditableIndex(pos, true);
+    if (pos > old_len)
+    {
+        pos = old_len;
+        // Should not happen,
+        // if you encounter this, check where wrong position comes from
+        llassert(false);
+    }
 
 	segment_set_t::iterator seg_iter = getEditableSegIterContaining(pos);
 
-- 
cgit v1.2.3