Browse Source

public: ParseFile drops const qualifier, return -1 length on overflow

As we usually put allocated data to ParseFile, we don't need const qualifier
pull/2/head
Alibek Omarov 3 years ago committed by a1batross
parent
commit
378c4f30f3
  1. 5
      public/crtlib.c
  2. 2
      public/crtlib.h

5
public/crtlib.c

@ -995,7 +995,7 @@ COM_ParseFile
text parser text parser
============== ==============
*/ */
const char *_COM_ParseFileSafe( const char *data, char *token, const int size, unsigned int flags, int *plen ) char *_COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *plen )
{ {
int c, len = 0; int c, len = 0;
qboolean overflow = false; qboolean overflow = false;
@ -1054,6 +1054,7 @@ skipwhite:
token[len] = (byte)*data; token[len] = (byte)*data;
len++; len++;
} }
else overflow = true;
data++; data++;
continue; continue;
@ -1071,6 +1072,7 @@ skipwhite:
token[len] = c; token[len] = c;
len++; len++;
} }
else overflow = true;
} }
} }
@ -1102,6 +1104,7 @@ skipwhite:
token[len] = c; token[len] = c;
len++; len++;
} }
else overflow = true;
data++; data++;
c = ((byte)*data); c = ((byte)*data);

2
public/crtlib.h

@ -95,7 +95,7 @@ char COM_Hex2Char( uint8_t hex );
void COM_Hex2String( uint8_t hex, char *str ); void COM_Hex2String( uint8_t hex, char *str );
#define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 ) #define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 )
#define COM_CheckStringEmpty( string ) ( ( !*string ) ? 0 : 1 ) #define COM_CheckStringEmpty( string ) ( ( !*string ) ? 0 : 1 )
const char *_COM_ParseFileSafe( const char *data, char *token, const int size, unsigned int flags, int *len ); char *_COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *len );
#define COM_ParseFile( data, token, size ) _COM_ParseFileSafe( data, token, size, 0, NULL ) #define COM_ParseFile( data, token, size ) _COM_ParseFileSafe( data, token, size, 0, NULL )
#define COM_ParseFileLegacy( data, token ) COM_ParseFileSafe( data, token, INT_MAX ) #define COM_ParseFileLegacy( data, token ) COM_ParseFileSafe( data, token, INT_MAX )
int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive ); int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive );

Loading…
Cancel
Save