From 312279227a6de533ea17b89df5ab55f4535f5caa Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Mon, 23 Mar 2020 21:17:04 -0400
Subject: [PATCH] Fix some small string bugs

---
 indra/llappearance/llpolymorph.cpp |  4 ++--
 indra/llmessage/llcachename.cpp    |  8 ++++----
 indra/llui/lltexteditor.cpp        |  4 ++--
 indra/llui/lltimectrl.cpp          | 26 ++++++++++++++------------
 indra/newview/llappviewer.cpp      |  4 ++--
 5 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/indra/llappearance/llpolymorph.cpp b/indra/llappearance/llpolymorph.cpp
index c6f5cac4b8a..66e9751f062 100644
--- a/indra/llappearance/llpolymorph.cpp
+++ b/indra/llappearance/llpolymorph.cpp
@@ -384,8 +384,8 @@ BOOL LLPolyMorphTarget::setInfo(LLPolyMorphTargetInfo* info)
 	if (!mMorphData)
 	{
 		const std::string driven_tag = "_Driven";
-		U32 pos = morph_param_name.find(driven_tag);
-		if (pos > 0)
+		size_t pos = morph_param_name.find(driven_tag);
+		if (pos != std::string::npos && pos > 0)
 		{
 			morph_param_name = morph_param_name.substr(0,pos);
 			mMorphData = mMesh->getMorphData(morph_param_name);
diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp
index 66bd85f4e6a..0064b10fefb 100644
--- a/indra/llmessage/llcachename.cpp
+++ b/indra/llmessage/llcachename.cpp
@@ -560,13 +560,13 @@ std::string LLCacheName::buildLegacyName(const std::string& complete_name)
 {
 	//boost::regexp was showing up in the crashreporter, so doing  
 	//painfully manual parsing using substr. LF
-	S32 open_paren = complete_name.rfind(" (");
-	S32 close_paren = complete_name.rfind(')');
+	size_t open_paren = complete_name.rfind(" (");
+	size_t close_paren = complete_name.rfind(')');
 
 	if (open_paren != std::string::npos &&
 		close_paren == complete_name.length()-1)
 	{
-		S32 length = close_paren - open_paren - 2;
+		size_t length = close_paren - open_paren - 2;
 		std::string legacy_name = complete_name.substr(open_paren+2, length);
 		
 		if (legacy_name.length() > 0)
@@ -575,7 +575,7 @@ std::string LLCacheName::buildLegacyName(const std::string& complete_name)
 			LLStringUtil::toUpper(cap_letter);
 			legacy_name = cap_letter + legacy_name.substr(1);
 	
-			S32 separator = legacy_name.find('.');
+			size_t separator = legacy_name.find('.');
 
 			if (separator != std::string::npos)
 			{
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 0a67d8f73b0..73dbac87f9f 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -362,10 +362,10 @@ void LLTextEditor::selectNext(const std::string& search_text_in, BOOL case_insen
 		}
 	}
 	
-	S32 loc = text.find(search_text,mCursorPos);
+	size_t loc = text.find(search_text,mCursorPos);
 	
 	// If Maybe we wrapped, search again
-	if (wrap && (-1 == loc))
+	if (wrap && (std::string::npos == loc))
 	{	
 		loc = text.find(search_text);
 	}
diff --git a/indra/llui/lltimectrl.cpp b/indra/llui/lltimectrl.cpp
index 516057f8fd5..f76c6bc92e5 100644
--- a/indra/llui/lltimectrl.cpp
+++ b/indra/llui/lltimectrl.cpp
@@ -322,19 +322,21 @@ LLTimeCtrl::EEditingPart LLTimeCtrl::getEditingPart()
 	S32 cur_pos = mEditor->getCursor();
 	std::string time_str = mEditor->getText();
 
-	S32 colon_index = time_str.find_first_of(':');
-
-	if (cur_pos <= colon_index)
-	{
-		return HOURS;
-	}
-	else if (cur_pos > colon_index && cur_pos <= (S32)(time_str.length() - AMPM_LEN))
+	size_t colon_index = time_str.find_first_of(':');
+	if (colon_index != std::string::npos)
 	{
-		return MINUTES;
-	}
-	else if (cur_pos > (S32)(time_str.length() - AMPM_LEN))
-	{
-		return DAYPART;
+		if (cur_pos <= colon_index)
+		{
+			return HOURS;
+		}
+		else if (cur_pos > colon_index&& cur_pos <= (S32)(time_str.length() - AMPM_LEN))
+		{
+			return MINUTES;
+		}
+		else if (cur_pos > (S32)(time_str.length() - AMPM_LEN))
+		{
+			return DAYPART;
+		}
 	}
 
 	return NONE;
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index ce7414983d4..18af7c8c5f1 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -4333,8 +4333,8 @@ bool LLAppViewer::initCache()
 		{
 			old_vfs_data_file = gDirUtilp->add(dir, found_file);
 
-			S32 start_pos = found_file.find_last_of('.');
-			if (start_pos > 0)
+			size_t start_pos = found_file.find_last_of('.');
+			if (start_pos != std::string::npos && start_pos > 0)
 			{
 				sscanf(found_file.substr(start_pos+1).c_str(), "%d", &old_salt);
 			}
-- 
GitLab