use safe string in GetIndexedShader

fix custom shader overflow check
This commit is contained in:
Garux 2021-01-19 22:12:53 +03:00
parent c3437b7833
commit cbeccc7e3a
3 changed files with 6 additions and 13 deletions

View File

@ -52,7 +52,7 @@ public:
}
StringFixedSize& operator=( const char* string ){
return (*this)( string );
return operator()( string );
}
template<typename ... Args>

View File

@ -519,8 +519,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ){
}
/* error check */
if ( ( strlen( mapName ) + 1 + 32 ) > MAX_QPATH ) {
Error( "Custom shader name length (%d) exceeded. Shorten your map name.\n", MAX_QPATH );
if ( ( strlen( mapName ) + 1 + 32 ) >= MAX_QPATH ) {
Error( "Custom shader name length (%d) exceeded. Shorten your map name.\n", MAX_QPATH - 1 );
}
/* do some bad find-replace */

View File

@ -787,7 +787,6 @@ byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t
shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoints, byte *shaderIndexes ){
int i;
byte minShaderIndex, maxShaderIndex;
char shader[ MAX_QPATH ];
shaderInfo_t *si;
@ -821,16 +820,10 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi
}
}
/* make a shader name */
if ( minShaderIndex == maxShaderIndex ) {
sprintf( shader, "textures/%s_%d", im->shader, maxShaderIndex );
}
else{
sprintf( shader, "textures/%s_%dto%d", im->shader, minShaderIndex, maxShaderIndex );
}
/* get the shader */
si = ShaderInfoForShader( shader );
si = ShaderInfoForShader( ( minShaderIndex == maxShaderIndex )?
String64()( "textures/", im->shader, '_', int(maxShaderIndex) ):
String64()( "textures/", im->shader, '_', int(minShaderIndex), "to", int(maxShaderIndex) ) );
/* inherit a few things from parent shader */
if ( parent->globalTexture ) {