From 9c2d06e150c8e68fc4eba315862987c458c63ce2 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 26 Nov 2004 20:48:06 +0000 Subject: [PATCH] string::find() result is a size_t, not an int unwrap conditional return after error, or the output string will just be overwritten --- stepmania/src/ScreenPackages.cpp | 45 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/stepmania/src/ScreenPackages.cpp b/stepmania/src/ScreenPackages.cpp index c6f77f3e6b..2f678b3781 100644 --- a/stepmania/src/ScreenPackages.cpp +++ b/stepmania/src/ScreenPackages.cpp @@ -598,30 +598,31 @@ void ScreenPackages::HTTPUpdate() int HeaderEnd = m_sBUFFER.find("\n\n"); if( HeaderEnd == m_sBUFFER.npos ) HeaderEnd = m_sBUFFER.find("\r\n\r\n"); - if( HeaderEnd != m_sBUFFER.npos ) + if( HeaderEnd == m_sBUFFER.npos ) + return; + + size_t i = m_sBUFFER.find(" "); + size_t j = m_sBUFFER.find(" ",i+1); + size_t k = m_sBUFFER.find("\n",j+1); + if ( i == string::npos || j == string::npos || k == string::npos ) { - int i = m_sBUFFER.find(" "); - int j = m_sBUFFER.find(" ",i+1); - int k = m_sBUFFER.find("\n",j+1); - if ( i == string::npos || j == string::npos || k == string::npos ) - { - m_iResponseCode = -100; - m_sResponseName = "Malformed response."; - } - m_iResponseCode = atoi(m_sBUFFER.substr(i+1,j-i).c_str()); - m_sResponseName = m_sBUFFER.substr( j+1, k-j).c_str(); - - i = m_sBUFFER.find("Content-Length:"); - j = m_sBUFFER.find("\n", i+1 ); - - if( i > 0 ) - m_iTotalBytes = atoi(m_sBUFFER.substr(i+16,j-i).c_str()); - else - m_iTotalBytes = -1; //We don't know, so go until disconnect - - m_bGotHeader = true; - m_sBUFFER = m_sBUFFER.substr( HeaderEnd + 4 ); + m_iResponseCode = -100; + m_sResponseName = "Malformed response."; + return; } + m_iResponseCode = atoi(m_sBUFFER.substr(i+1,j-i).c_str()); + m_sResponseName = m_sBUFFER.substr( j+1, k-j).c_str(); + + i = m_sBUFFER.find("Content-Length:"); + j = m_sBUFFER.find("\n", i+1 ); + + if( i > 0 ) + m_iTotalBytes = atoi(m_sBUFFER.substr(i+16,j-i).c_str()); + else + m_iTotalBytes = -1; //We don't know, so go until disconnect + + m_bGotHeader = true; + m_sBUFFER = m_sBUFFER.substr( HeaderEnd + 4 ); } else {