aboutsummaryrefslogtreecommitdiff
path: root/mp/src/tier1/utlbuffer.cpp
diff options
context:
space:
mode:
authorJohn Schoenick <[email protected]>2015-09-09 18:35:41 -0700
committerJohn Schoenick <[email protected]>2015-09-09 18:35:41 -0700
commit0d8dceea4310fde5706b3ce1c70609d72a38efdf (patch)
treec831ef32c2c801a5c5a80401736b52c7b5a528ec /mp/src/tier1/utlbuffer.cpp
parentUpdated the SDK with the latest code from the TF and HL2 branches. (diff)
downloadsource-sdk-2013-0d8dceea4310fde5706b3ce1c70609d72a38efdf.tar.xz
source-sdk-2013-0d8dceea4310fde5706b3ce1c70609d72a38efdf.zip
Updated the SDK with the latest code from the TF and HL2 branches.HEADmaster
Diffstat (limited to 'mp/src/tier1/utlbuffer.cpp')
-rw-r--r--mp/src/tier1/utlbuffer.cpp35
1 files changed, 17 insertions, 18 deletions
diff --git a/mp/src/tier1/utlbuffer.cpp b/mp/src/tier1/utlbuffer.cpp
index 55dd8f6b..fc89d773 100644
--- a/mp/src/tier1/utlbuffer.cpp
+++ b/mp/src/tier1/utlbuffer.cpp
@@ -607,17 +607,19 @@ int CUtlBuffer::PeekDelimitedStringLength( CUtlCharConversion *pConv, bool bActu
//-----------------------------------------------------------------------------
// Reads a null-terminated string
//-----------------------------------------------------------------------------
-void CUtlBuffer::GetString( char* pString, int nMaxChars )
+void CUtlBuffer::GetStringInternal( char *pString, size_t maxLenInChars )
{
- if (!IsValid())
+ if ( !IsValid() )
{
*pString = 0;
return;
}
- if ( nMaxChars == 0 )
+ Assert( maxLenInChars != 0 );
+
+ if ( maxLenInChars == 0 )
{
- nMaxChars = INT_MAX;
+ return;
}
// Remember, this *includes* the null character
@@ -629,24 +631,21 @@ void CUtlBuffer::GetString( char* pString, int nMaxChars )
EatWhiteSpace();
}
- if ( nLen == 0 )
+ if ( nLen <= 0 )
{
*pString = 0;
m_Error |= GET_OVERFLOW;
return;
}
-
- // Strip off the terminating NULL
- if ( nLen <= nMaxChars )
- {
- Get( pString, nLen - 1 );
- pString[ nLen - 1 ] = 0;
- }
- else
+
+ const size_t nCharsToRead = min( (size_t)nLen, maxLenInChars ) - 1;
+
+ Get( pString, nCharsToRead );
+ pString[nCharsToRead] = 0;
+
+ if ( (size_t)nLen > (nCharsToRead + 1) )
{
- Get( pString, nMaxChars - 1 );
- pString[ nMaxChars - 1 ] = 0;
- SeekGet( SEEK_CURRENT, nLen - 1 - nMaxChars );
+ SeekGet( SEEK_CURRENT, nLen - (nCharsToRead + 1) );
}
// Read the terminating NULL in binary formats
@@ -731,7 +730,7 @@ void CUtlBuffer::GetDelimitedString( CUtlCharConversion *pConv, char *pString, i
{
if ( !IsText() || !pConv )
{
- GetString( pString, nMaxChars );
+ GetStringInternal( pString, nMaxChars );
return;
}
@@ -1041,7 +1040,7 @@ int CUtlBuffer::VaScanf( const char* pFmt, va_list list )
case 's':
{
char* s = va_arg( list, char * );
- GetString( s );
+ GetStringInternal( s, 256 );
}
break;