From 8fe66986e91d81f1de95dbeded7c23c4b8fca091 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Thu, 19 Mar 2020 15:59:30 -0400
Subject: [PATCH] Catch exceptions by const-ref

---
 indra/llaudio/llaudiodecodemgr.cpp    | 2 +-
 indra/llcommon/llsdserialize.cpp      | 4 ++--
 indra/llcorehttp/_httpservice.cpp     | 2 +-
 indra/llcorehttp/bufferarray.cpp      | 2 +-
 indra/llimage/llimagejpeg.cpp         | 2 +-
 indra/llimage/llpngwrapper.cpp        | 2 +-
 indra/llkdu/llimagej2ckdu.cpp         | 8 ++++----
 indra/llmath/llvolume.cpp             | 4 ++--
 indra/llmessage/llcorehttputil.cpp    | 4 ++--
 indra/llmessage/llhttpnode.cpp        | 8 ++++----
 indra/llprimitive/lldaeloader.cpp     | 4 ++--
 indra/llui/llurlregistry.cpp          | 2 +-
 indra/llvfs/lldir.cpp                 | 2 +-
 indra/llvfs/lldiriterator.cpp         | 2 +-
 indra/newview/llappcorehttp.cpp       | 4 ++--
 indra/newview/llappviewer.cpp         | 4 ++--
 indra/newview/llcommandlineparser.cpp | 6 +++---
 indra/newview/llcompilequeue.cpp      | 2 +-
 indra/newview/llimprocessing.cpp      | 2 +-
 indra/newview/llmainlooprepeater.cpp  | 2 +-
 indra/newview/llmeshrepository.cpp    | 2 +-
 indra/newview/llpanellogin.cpp        | 4 ++--
 indra/newview/llsecapi.cpp            | 2 +-
 indra/newview/llsechandler_basic.cpp  | 2 +-
 indra/newview/llviewernetwork.h       | 2 +-
 25 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/indra/llaudio/llaudiodecodemgr.cpp b/indra/llaudio/llaudiodecodemgr.cpp
index 6ab61689fd0..f11d11f547e 100644
--- a/indra/llaudio/llaudiodecodemgr.cpp
+++ b/indra/llaudio/llaudiodecodemgr.cpp
@@ -271,7 +271,7 @@ BOOL LLVorbisDecodeState::initDecode()
 		mWAVBuffer.reserve(size_guess);
 		mWAVBuffer.resize(WAV_HEADER_SIZE);
 	}
-	catch (std::bad_alloc)
+	catch (const std::bad_alloc&)
 	{
 		LL_WARNS("AudioEngine") << "Out of memory when trying to alloc buffer: " << size_guess << LL_ENDL;
 		delete mInFilep;
diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp
index 1ae7a6f4788..e1b13a1d05b 100644
--- a/indra/llcommon/llsdserialize.cpp
+++ b/indra/llcommon/llsdserialize.cpp
@@ -2244,13 +2244,13 @@ LLUZipHelper::EZipRresult LLUZipHelper::unzip_llsd(LLSD& data, std::istream& is,
 			istr.str(res_str);
 		}
 #ifdef LL_WINDOWS
-		catch (std::length_error)
+		catch (const std::length_error&)
 		{
 			free(result);
 			return ZR_SIZE_ERROR;
 		}
 #endif
-		catch (std::bad_alloc)
+		catch (const std::bad_alloc&)
 		{
 			free(result);
 			return ZR_MEM_ERROR;
diff --git a/indra/llcorehttp/_httpservice.cpp b/indra/llcorehttp/_httpservice.cpp
index 0b72b531860..0b8d4dbb817 100644
--- a/indra/llcorehttp/_httpservice.cpp
+++ b/indra/llcorehttp/_httpservice.cpp
@@ -318,7 +318,7 @@ void HttpService::threadRun(LLCoreInt::HttpThread * thread)
         {
             LOG_UNHANDLED_EXCEPTION("");
         }
-        catch (std::bad_alloc)
+        catch (const std::bad_alloc&)
         {
             LLMemory::logMemoryInfo(TRUE);
 
diff --git a/indra/llcorehttp/bufferarray.cpp b/indra/llcorehttp/bufferarray.cpp
index be534b3ce4f..78a4cb947ba 100644
--- a/indra/llcorehttp/bufferarray.cpp
+++ b/indra/llcorehttp/bufferarray.cpp
@@ -147,7 +147,7 @@ size_t BufferArray::append(const void * src, size_t len)
         {
             block = Block::alloc(BLOCK_ALLOC_SIZE);
         }
-        catch (std::bad_alloc)
+        catch (const std::bad_alloc&)
         {
             LLMemory::logMemoryInfo(TRUE);
 
diff --git a/indra/llimage/llimagejpeg.cpp b/indra/llimage/llimagejpeg.cpp
index eaccd62462b..eaa4bcb5850 100644
--- a/indra/llimage/llimagejpeg.cpp
+++ b/indra/llimage/llimagejpeg.cpp
@@ -315,7 +315,7 @@ bool LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time)
 		jpeg_destroy_decompress(&cinfo);
 	}
 
-	catch (std::bad_alloc)
+	catch (const std::bad_alloc&)
 	{
 		setLastError( "Out of memory");
 		jpeg_destroy_decompress(&cinfo);
diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp
index f298764cc07..1e51e7375e7 100644
--- a/indra/llimage/llpngwrapper.cpp
+++ b/indra/llimage/llpngwrapper.cpp
@@ -210,7 +210,7 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf
 		releaseResources();
 		return (FALSE);
 	}
-	catch (std::bad_alloc)
+	catch (const std::bad_alloc&)
 	{
 		mErrorMessage = "LLPngWrapper";
 		releaseResources();
diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp
index 4048b9a43d0..99b8e2c9bc4 100644
--- a/indra/llkdu/llimagej2ckdu.cpp
+++ b/indra/llkdu/llimagej2ckdu.cpp
@@ -483,7 +483,7 @@ bool LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco
 		base.setLastError(msg.what());
 		return false;
 	}
-	catch (kdu_exception kdu_value)
+	catch (const kdu_exception& kdu_value)
 	{
 		// KDU internally throws kdu_exception. It's possible that such an
 		// exception might leak out into our code. Catch kdu_exception
@@ -592,7 +592,7 @@ bool LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco
 				cleanupCodeStream();
 				return true; // done
 			}
-			catch (kdu_exception kdu_value)
+			catch (const kdu_exception& kdu_value)
 			{
 				// KDU internally throws kdu_exception. It's possible that such an
 				// exception might leak out into our code. Catch kdu_exception
@@ -795,7 +795,7 @@ bool LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
 		base.setLastError(msg.what());
 		return false;
 	}
-	catch (kdu_exception kdu_value)
+	catch (const kdu_exception& kdu_value)
 	{
 		// KDU internally throws kdu_exception. It's possible that such an
 		// exception might leak out into our code. Catch kdu_exception
@@ -829,7 +829,7 @@ bool LLImageJ2CKDU::getMetadata(LLImageJ2C &base)
 		base.setLastError(msg.what());
 		return false;
 	}
-	catch (kdu_exception kdu_value)
+	catch (const kdu_exception& kdu_value)
 	{
 		// KDU internally throws kdu_exception. It's possible that such an
 		// exception might leak out into our code. Catch kdu_exception
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 2ac1eb99ce7..675c59d4d5e 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -5288,7 +5288,7 @@ bool LLVolumeFace::cacheOptimize()
 		triangle_data.resize(mNumIndices / 3);
 		vertex_data.resize(mNumVertices);
 	}
-	catch (std::bad_alloc)
+	catch (const std::bad_alloc&)
 	{
 		LL_WARNS("LLVOLUME") << "Resize failed" << LL_ENDL;
 		return false;
@@ -5442,7 +5442,7 @@ bool LLVolumeFace::cacheOptimize()
 	{
 		new_idx.resize(mNumVertices, -1);
 	}
-	catch (std::bad_alloc)
+	catch (const std::bad_alloc&)
 	{
 		ll_aligned_free<64>(pos);
 		ll_aligned_free_16(wght);
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index 24387fbffd7..fdb441c6602 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -597,7 +597,7 @@ LLSD HttpCoroJSONHandler::handleSuccess(LLCore::HttpResponse * response, LLCore:
     {
         bas >> jsonRoot;
     }
-    catch (std::runtime_error e)
+    catch (const std::runtime_error& e)
     {   // deserialization failed.  Record the reason and pass back an empty map for markup.
         status = LLCore::HttpStatus(499, std::string(e.what()));
         return result;
@@ -625,7 +625,7 @@ LLSD HttpCoroJSONHandler::parseBody(LLCore::HttpResponse *response, bool &succes
     {
         bas >> jsonRoot;
     }
-    catch (std::runtime_error e)
+    catch (const std::runtime_error&)
     {   
         success = false;
         return LLSD();
diff --git a/indra/llmessage/llhttpnode.cpp b/indra/llmessage/llhttpnode.cpp
index 04b34a296c1..612c947a596 100644
--- a/indra/llmessage/llhttpnode.cpp
+++ b/indra/llmessage/llhttpnode.cpp
@@ -125,7 +125,7 @@ void LLHTTPNode::get(LLHTTPNode::ResponsePtr response, const LLSD& context) cons
 	{
 		response->result(simpleGet());
 	}
-	catch (NotImplemented)
+	catch (const NotImplemented&)
 	{
 		response->methodNotAllowed();
 	}
@@ -138,7 +138,7 @@ void LLHTTPNode::put(LLHTTPNode::ResponsePtr response, const LLSD& context, cons
 	{
 		response->result(simplePut(input));
 	}
-	catch (NotImplemented)
+	catch (const NotImplemented&)
 	{
 		response->methodNotAllowed();
 	}
@@ -151,7 +151,7 @@ void LLHTTPNode::post(LLHTTPNode::ResponsePtr response, const LLSD& context, con
 	{
 		response->result(simplePost(input));
 	}
-	catch (NotImplemented)
+	catch (const NotImplemented&)
 	{
 		response->methodNotAllowed();
 	}
@@ -164,7 +164,7 @@ void LLHTTPNode::del(LLHTTPNode::ResponsePtr response, const LLSD& context) cons
     {
 	response->result(simpleDel(context));
     }
-    catch (NotImplemented)
+    catch (const NotImplemented&)
     {
 	response->methodNotAllowed();
     }
diff --git a/indra/llprimitive/lldaeloader.cpp b/indra/llprimitive/lldaeloader.cpp
index 139f48fef80..36ad8b3da45 100644
--- a/indra/llprimitive/lldaeloader.cpp
+++ b/indra/llprimitive/lldaeloader.cpp
@@ -1121,9 +1121,9 @@ std::string LLDAELoader::preprocessDAE(std::string filename)
 			next++;
 		}
 	}
-	catch (boost::regex_error &)
+	catch (const boost::regex_error& err)
 	{
-		LL_INFOS() << "Regex error" << LL_ENDL;
+		LL_INFOS() << "Regex error: " << err.what()  << LL_ENDL;
 	}
 
 	return buffer;
diff --git a/indra/llui/llurlregistry.cpp b/indra/llui/llurlregistry.cpp
index b526c1df085..3ffda3e44ee 100644
--- a/indra/llui/llurlregistry.cpp
+++ b/indra/llui/llurlregistry.cpp
@@ -118,7 +118,7 @@ static bool matchRegex(const char *text, boost::regex regex, U32 &start, U32 &en
 	{
 		found = boost::regex_search(text, result, regex);
 	}
-	catch (std::runtime_error &)
+	catch (const std::runtime_error &)
 	{
 		return false;
 	}
diff --git a/indra/llvfs/lldir.cpp b/indra/llvfs/lldir.cpp
index 2076ce334e4..00bcb32253a 100644
--- a/indra/llvfs/lldir.cpp
+++ b/indra/llvfs/lldir.cpp
@@ -217,7 +217,7 @@ U32 LLDir::deleteDirAndContents(const std::string& dir_name)
 		  }
 	   }
 	}
-	catch (boost::filesystem::filesystem_error &er)
+	catch (const boost::filesystem::filesystem_error &er)
 	{ 
 		LL_WARNS() << "Failed to delete " << dir_name << " with error " << er.code().message() << LL_ENDL;
 	} 
diff --git a/indra/llvfs/lldiriterator.cpp b/indra/llvfs/lldiriterator.cpp
index 3eb64e69d9a..7f9fb85d62e 100644
--- a/indra/llvfs/lldiriterator.cpp
+++ b/indra/llvfs/lldiriterator.cpp
@@ -97,7 +97,7 @@ LLDirIterator::Impl::Impl(const std::string &dirname, const std::string &mask)
 	{
 		mFilterExp.assign(exp);
 	}
-	catch (boost::regex_error& e)
+	catch (const boost::regex_error& e)
 	{
 		LL_WARNS() << "\"" << exp << "\" is not a valid regular expression: "
 				<< e.what() << LL_ENDL;
diff --git a/indra/newview/llappcorehttp.cpp b/indra/newview/llappcorehttp.cpp
index afa44149684..36299c0f544 100644
--- a/indra/newview/llappcorehttp.cpp
+++ b/indra/newview/llappcorehttp.cpp
@@ -539,7 +539,7 @@ LLCore::HttpStatus LLAppCoreHttp::sslVerify(const std::string &url,
 		// don't validate hostname.  Let libcurl do it instead.  That way, it'll handle redirects
 		store->validate(VALIDATION_POLICY_SSL & (~VALIDATION_POLICY_HOSTNAME), chain, validation_params);
 	}
-	catch (LLCertValidationTrustException &cert_exception)
+	catch (const LLCertValidationTrustException &cert_exception)
 	{
 		// this exception is is handled differently than the general cert
 		// exceptions, as we allow the user to actually add the certificate
@@ -555,7 +555,7 @@ LLCore::HttpStatus LLAppCoreHttp::sslVerify(const std::string &url,
 		// We should probably have a more generic way of passing information
 		// back to the error handlers.
 	}
-	catch (LLCertException &cert_exception)
+	catch (const LLCertException &cert_exception)
 	{
 		result = LLCore::HttpStatus(LLCore::HttpStatus::EXT_CURL_EASY, CURLE_SSL_PEER_CERTIFICATE);
 		result.setMessage(cert_exception.what());
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 46434a582d3..ce7414983d4 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1146,7 +1146,7 @@ bool LLAppViewer::init()
 	try {
 		initializeSecHandler();
 	}
-	catch (LLProtectedDataException ex)
+	catch (const LLProtectedDataException&)
 	{
 	  LLNotificationsUtil::add("CorruptedProtectedDataStore");
 	}
@@ -1360,7 +1360,7 @@ bool LLAppViewer::frame()
 		{
 			LOG_UNHANDLED_EXCEPTION("");
 		}
-		catch (std::bad_alloc)
+		catch (const std::bad_alloc&)
 		{
 			LLMemory::logMemoryInfo(TRUE);
 			LLFloaterMemLeak* mem_leak_instance = LLFloaterReg::findTypedInstance<LLFloaterMemLeak>("mem_leaking");
diff --git a/indra/newview/llcommandlineparser.cpp b/indra/newview/llcommandlineparser.cpp
index fe14bc081f2..0074e365934 100644
--- a/indra/newview/llcommandlineparser.cpp
+++ b/indra/newview/llcommandlineparser.cpp
@@ -302,19 +302,19 @@ bool LLCommandLineParser::parseAndStoreResults(po::command_line_parser& clp)
         po::basic_parsed_options<char> opts = clp.run();
         po::store(opts, gVariableMap);
     }
-    catch(po::error& e)
+    catch(const po::error& e)
     {
         LL_WARNS() << "Caught Error:" << e.what() << LL_ENDL;
 		mErrorMsg = e.what();
         return false;
     }
-    catch(LLCLPError& e)
+    catch(const LLCLPError& e)
     {
         LL_WARNS() << "Caught Error:" << e.what() << LL_ENDL;
 		mErrorMsg = e.what();
         return false;
     }
-    catch(LLCLPLastOption&) 
+    catch(const LLCLPLastOption&)
     {
 		// This exception means a token was read after an option 
 		// that must be the last option was reached (see url and slurl options)
diff --git a/indra/newview/llcompilequeue.cpp b/indra/newview/llcompilequeue.cpp
index 76e16f5a1ff..200a04d49cc 100644
--- a/indra/newview/llcompilequeue.cpp
+++ b/indra/newview/llcompilequeue.cpp
@@ -802,7 +802,7 @@ void LLFloaterScriptQueue::objectScriptProcessingQueueCoro(std::string action, L
         floater->addStringMessage("Done");
         floater->getChildView("close")->setEnabled(TRUE);
     }
-    catch (LLCheckedHandleBase::Stale &)
+    catch (const LLCheckedHandleBase::Stale &)
     {
         // This is expected.  It means that floater has been closed before 
         // processing was completed.
diff --git a/indra/newview/llimprocessing.cpp b/indra/newview/llimprocessing.cpp
index 7c41468b779..fbd069a54d5 100644
--- a/indra/newview/llimprocessing.cpp
+++ b/indra/newview/llimprocessing.cpp
@@ -396,7 +396,7 @@ static bool parse_lure_bucket(const std::string& bucket,
         ly = boost::lexical_cast<S32>((*(++iter)).c_str());
         lz = boost::lexical_cast<S32>((*(++iter)).c_str());
     }
-    catch (boost::bad_lexical_cast&)
+    catch (const boost::bad_lexical_cast&)
     {
         LL_WARNS("parse_lure_bucket")
             << "Couldn't parse lure bucket."
diff --git a/indra/newview/llmainlooprepeater.cpp b/indra/newview/llmainlooprepeater.cpp
index 6736e9a950d..7c580252aa5 100644
--- a/indra/newview/llmainlooprepeater.cpp
+++ b/indra/newview/llmainlooprepeater.cpp
@@ -80,7 +80,7 @@ bool LLMainLoopRepeater::onMessage(LLSD const & event)
 {
 	try {
 		mQueue->pushFront(event);
-	} catch(LLThreadSafeQueueError & e) {
+	} catch(const LLThreadSafeQueueError & e) {
 		LL_WARNS() << "could not repeat message (" << e.what() << ")" << 
 			event.asString() << LL_ENDL;
 	}
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index 84c189f4988..b5cbc01214a 100644
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -1919,7 +1919,7 @@ EMeshProcessingResult LLMeshRepoThread::lodReceived(const LLVolumeParams& mesh_p
 		std::string mesh_string((char*)data, data_size);
 		stream.str(mesh_string);
 	}
-	catch (std::bad_alloc)
+	catch (const std::bad_alloc&)
 	{
 		// out of memory, we won't be able to process this mesh
 		return MESH_OUT_OF_MEMORY;
diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp
index 224cec9650e..e440071cf7f 100644
--- a/indra/newview/llpanellogin.cpp
+++ b/indra/newview/llpanellogin.cpp
@@ -999,7 +999,7 @@ void LLPanelLogin::onClickConnect(void *)
 		{
 			LLGridManager::getInstance()->setGridChoice(combo_val.asString());
 		}
-		catch (LLInvalidGridName ex)
+		catch (const LLInvalidGridName& ex)
 		{
 			LLSD args;
 			args["GRID"] = ex.name();
@@ -1206,7 +1206,7 @@ void LLPanelLogin::updateServer()
 			// grid changed so show new splash screen (possibly)
 			loadLoginPage();
 		}
-		catch (LLInvalidGridName ex)
+		catch (const LLInvalidGridName& ex)
 		{
 			LL_WARNS("AppInit")<<"server '"<<ex.name()<<"' selection failed"<<LL_ENDL;
 			LLSD args;
diff --git a/indra/newview/llsecapi.cpp b/indra/newview/llsecapi.cpp
index 72d7cf1e452..0ef13d97418 100644
--- a/indra/newview/llsecapi.cpp
+++ b/indra/newview/llsecapi.cpp
@@ -64,7 +64,7 @@ void initializeSecHandler()
 		{
 			handler->init();
 		}
-		catch (LLProtectedDataException e)
+		catch (const LLProtectedDataException& e)
 		{
 			exception_msg = e.what();
 		}
diff --git a/indra/newview/llsechandler_basic.cpp b/indra/newview/llsechandler_basic.cpp
index 55e49100c35..53888626e56 100644
--- a/indra/newview/llsechandler_basic.cpp
+++ b/indra/newview/llsechandler_basic.cpp
@@ -605,7 +605,7 @@ void LLBasicCertificateStore::load_from_file(const std::string& filename)
                                 << LL_ENDL;
                         loaded++;
                     }
-                    catch (LLCertException& cert_exception)
+                    catch (const LLCertException& cert_exception)
                     {
                         LLSD cert_info(cert_exception.getCertData());
                         LL_DEBUGS("SECAPI_BADCERT","SECAPI") << "invalid certificate (" << cert_exception.what() << "): " << cert_info << LL_ENDL;
diff --git a/indra/newview/llviewernetwork.h b/indra/newview/llviewernetwork.h
index b8ff494b8b0..4c87720374d 100644
--- a/indra/newview/llviewernetwork.h
+++ b/indra/newview/llviewernetwork.h
@@ -38,7 +38,7 @@ class LLInvalidGridName
 	LLInvalidGridName(std::string grid) : mGrid(grid)
 	{
 	}
-	std::string name() { return mGrid; }
+	std::string name() const { return mGrid; }
 protected:
 	std::string mGrid;
 };
-- 
GitLab