Browse Source

engine: common: test ParseFile length return value

pull/2/head
Alibek Omarov 3 years ago committed by a1batross
parent
commit
004e190435
  1. 33
      engine/common/common.c

33
engine/common/common.c

@ -464,14 +464,14 @@ qboolean COM_ParseVector( char **pfile, float *v, size_t size )
if( size == 1 ) if( size == 1 )
{ {
*pfile = COM_ParseFile( *pfile, token ); *pfile = COM_ParseFile( *pfile, token, sizeof( token ));
v[0] = Q_atof( token ); v[0] = Q_atof( token );
return true; return true;
} }
saved = *pfile; saved = *pfile;
if(( *pfile = COM_ParseFile( *pfile, token )) == NULL ) if(( *pfile = COM_ParseFile( *pfile, token, sizeof( token ))) == NULL )
return false; return false;
if( token[0] == '(' ) if( token[0] == '(' )
@ -480,13 +480,13 @@ qboolean COM_ParseVector( char **pfile, float *v, size_t size )
for( i = 0; i < size; i++ ) for( i = 0; i < size; i++ )
{ {
*pfile = COM_ParseFile( *pfile, token ); *pfile = COM_ParseFile( *pfile, token, sizeof( token ));
v[i] = Q_atof( token ); v[i] = Q_atof( token );
} }
if( !bracket ) return true; // done if( !bracket ) return true; // done
if(( *pfile = COM_ParseFile( *pfile, token )) == NULL ) if(( *pfile = COM_ParseFile( *pfile, token, sizeof( token ))) == NULL )
return false; return false;
if( token[0] == ')' ) if( token[0] == ')' )
@ -1170,26 +1170,27 @@ void GAME_EXPORT pfnResetTutorMessageDecayData( void )
void Test_RunCommon( void ) void Test_RunCommon( void )
{ {
char *file = (char *)"q asdf \"qwerty\" \"f \\\"f\" meowmeow\n// comment \"stuff ignored\"\nbark"; char *file = (char *)"q asdf \"qwerty\" \"f \\\"f\" meowmeow\n// comment \"stuff ignored\"\nbark";
int len;
char buf[5]; char buf[5];
Msg( "Checking COM_ParseFile...\n" ); Msg( "Checking COM_ParseFile...\n" );
file = COM_ParseFileSafe( file, buf, sizeof( buf )); file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len );
TASSERT( !Q_strcmp( buf, "q" )); TASSERT( !Q_strcmp( buf, "q" ) && len == 1);
file = COM_ParseFileSafe( file, buf, sizeof( buf )); file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len );
TASSERT( !Q_strcmp( buf, "asdf" )); TASSERT( !Q_strcmp( buf, "asdf" ) && len == 4);
file = COM_ParseFileSafe( file, buf, sizeof( buf )); file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len );
TASSERT( !Q_strcmp( buf, "qwer" )); TASSERT( !Q_strcmp( buf, "qwer" ) && len == -1);
file = COM_ParseFileSafe( file, buf, sizeof( buf )); file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len );
TASSERT( !Q_strcmp( buf, "f \"f" )); TASSERT( !Q_strcmp( buf, "f \"f" ) && len == 4);
file = COM_ParseFileSafe( file, buf, sizeof( buf )); file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len );
TASSERT( !Q_strcmp( buf, "meow" )); TASSERT( !Q_strcmp( buf, "meow" ) && len == -1);
file = COM_ParseFileSafe( file, buf, sizeof( buf )); file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len );
TASSERT( !Q_strcmp( buf, "bark" )); TASSERT( !Q_strcmp( buf, "bark" ) && len == 4);
} }
#endif #endif

Loading…
Cancel
Save