ref_gl: simplified strings operations.

This commit is contained in:
Andrey Akhmichin 2020-11-29 05:39:10 +05:00 committed by Alibek Omarov
parent 63d8794902
commit 5f54582692
2 changed files with 12 additions and 6 deletions

View File

@ -1299,13 +1299,17 @@ GL_CheckTexName
*/
qboolean GL_CheckTexName( const char *name )
{
int len;
if( !COM_CheckString( name ))
return false;
len = Q_strlen( name );
// because multi-layered textures can exceed name string
if( Q_strlen( name ) >= sizeof( gl_textures->name ))
if( len >= sizeof( gl_textures->name ))
{
gEngfuncs.Con_Printf( S_ERROR "LoadTexture: too long name %s (%d)\n", name, Q_strlen( name ));
gEngfuncs.Con_Printf( S_ERROR "LoadTexture: too long name %s (%d)\n", name, len );
return false;
}
@ -1529,7 +1533,7 @@ int GL_LoadTextureArray( const char **names, int flags )
for( i = 0; i < numLayers; i++ )
{
COM_FileBase( names[i], basename );
Q_strncat( name, va( "%s", basename ), sizeof( name ));
Q_strncat( name, basename, sizeof( name ) );
if( i != ( numLayers - 1 )) Q_strncat( name, "|", sizeof( name ));
}

View File

@ -412,7 +412,7 @@ void R_SetupSky( const char *skyboxname )
{
char loadname[MAX_STRING];
char sidename[MAX_STRING];
int i, result;
int i, result, len;
if( !COM_CheckString( skyboxname ))
{
@ -424,8 +424,10 @@ void R_SetupSky( const char *skyboxname )
COM_StripExtension( loadname );
// kill the underline suffix to find them manually later
if( loadname[Q_strlen( loadname ) - 1] == '_' )
loadname[Q_strlen( loadname ) - 1] = '\0';
len = Q_strlen( loadname );
if( loadname[len - 1] == '_' )
loadname[len - 1] = '\0';
result = CheckSkybox( loadname );
// to prevent infinite recursion if default skybox was missed