Handle exceptions in int conversions (#2092)

* RageUtil: Add exception-safe wrappers around std::stoi, stol, stoll

* Replace use of std::stoi with exception-safe StringToInt
This commit is contained in:
Gareth Francis
2021-02-15 12:36:51 -08:00
committed by GitHub
parent c7c54bb013
commit aeb5c7598f
25 changed files with 124 additions and 73 deletions
+3 -3
View File
@@ -630,14 +630,14 @@ void ScreenPackages::HTTPUpdate()
m_sResponseName = "Malformed response.";
return;
}
m_iResponseCode = std::stoi(m_sBUFFER.substr(i+1,j-i));
m_iResponseCode = StringToInt(m_sBUFFER.substr(i+1,j-i));
m_sResponseName = m_sBUFFER.substr( j+1, k-j );
i = m_sBUFFER.find("Content-Length:");
j = m_sBUFFER.find("\n", i+1 );
if( i != string::npos )
m_iTotalBytes = std::stoi(m_sBUFFER.substr(i+16,j-i));
m_iTotalBytes = StringToInt(m_sBUFFER.substr(i+16,j-i));
else
m_iTotalBytes = -1; //We don't know, so go until disconnect
@@ -704,7 +704,7 @@ bool ScreenPackages::ParseHTTPAddress( const RString &URL, RString &sProto, RStr
sServer = asMatches[1];
if( asMatches[3] != "" )
{
iPort = std::stoi(asMatches[3]);
iPort = StringToInt(asMatches[3]);
if( iPort == 0 )
return false;
}