Port COM_ParseExt fixes to CommaParse

This commit is contained in:
Zack Middleton 2014-08-28 20:34:05 -05:00
parent 1d95ef210e
commit e742952db8
2 changed files with 12 additions and 16 deletions

View file

@ -1443,12 +1443,15 @@ static char *CommaParse( char **data_p ) {
// skip double slash comments
if ( c == '/' && data[1] == '/' )
{
while (*data && *data != '\n')
data += 2;
while (*data && *data != '\n') {
data++;
}
}
// skip /* */ comments
else if ( c=='/' && data[1] == '*' )
{
data += 2;
while ( *data && ( *data != '*' || data[1] != '/' ) )
{
data++;
@ -1481,7 +1484,7 @@ static char *CommaParse( char **data_p ) {
*data_p = ( char * ) data;
return com_token;
}
if (len < MAX_TOKEN_CHARS)
if (len < MAX_TOKEN_CHARS - 1)
{
com_token[len] = c;
len++;
@ -1492,7 +1495,7 @@ static char *CommaParse( char **data_p ) {
// parse a regular word
do
{
if (len < MAX_TOKEN_CHARS)
if (len < MAX_TOKEN_CHARS - 1)
{
com_token[len] = c;
len++;
@ -1501,11 +1504,6 @@ static char *CommaParse( char **data_p ) {
c = *data;
} while (c>32 && c != ',' );
if (len == MAX_TOKEN_CHARS)
{
// ri.Printf (PRINT_DEVELOPER, "Token exceeded %i chars, discarded.\n", MAX_TOKEN_CHARS);
len = 0;
}
com_token[len] = 0;
*data_p = ( char * ) data;

View file

@ -3007,12 +3007,15 @@ static char *CommaParse( char **data_p ) {
// skip double slash comments
if ( c == '/' && data[1] == '/' )
{
while (*data && *data != '\n')
data += 2;
while (*data && *data != '\n') {
data++;
}
}
// skip /* */ comments
else if ( c=='/' && data[1] == '*' )
{
data += 2;
while ( *data && ( *data != '*' || data[1] != '/' ) )
{
data++;
@ -3045,7 +3048,7 @@ static char *CommaParse( char **data_p ) {
*data_p = ( char * ) data;
return com_token;
}
if (len < MAX_TOKEN_CHARS)
if (len < MAX_TOKEN_CHARS - 1)
{
com_token[len] = c;
len++;
@ -3056,7 +3059,7 @@ static char *CommaParse( char **data_p ) {
// parse a regular word
do
{
if (len < MAX_TOKEN_CHARS)
if (len < MAX_TOKEN_CHARS - 1)
{
com_token[len] = c;
len++;
@ -3065,11 +3068,6 @@ static char *CommaParse( char **data_p ) {
c = *data;
} while (c>32 && c != ',' );
if (len == MAX_TOKEN_CHARS)
{
// ri.Printf (PRINT_DEVELOPER, "Token exceeded %i chars, discarded.\n", MAX_TOKEN_CHARS);
len = 0;
}
com_token[len] = 0;
*data_p = ( char * ) data;