Skip to content

Commit

Permalink
Port COM_ParseExt fixes to CommaParse
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed Aug 29, 2014
1 parent 1d95ef2 commit e742952
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
14 changes: 6 additions & 8 deletions code/renderergl1/tr_image.c
Expand Up @@ -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++;
Expand Down Expand Up @@ -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++;
Expand All @@ -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++;
Expand All @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions code/renderergl2/tr_image.c
Expand Up @@ -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++;
Expand Down Expand Up @@ -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++;
Expand All @@ -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++;
Expand All @@ -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;
Expand Down

0 comments on commit e742952

Please sign in to comment.