From f3c26c791fdfbdf4eb7928a16602367c23c280ee Mon Sep 17 00:00:00 2001 From: Garux Date: Thu, 21 Jan 2021 16:08:53 +0300 Subject: [PATCH] use safe strings more --- tools/quake3/common/inout.cpp | 2 -- tools/quake3/q3map2/bsp.cpp | 3 +-- tools/quake3/q3map2/map.cpp | 5 +---- tools/quake3/q3map2/model.cpp | 7 +++---- tools/quake3/q3map2/patch.cpp | 7 ++----- tools/quake3/q3map2/q3map2.h | 2 +- tools/quake3/q3map2/surface.cpp | 2 +- 7 files changed, 9 insertions(+), 19 deletions(-) diff --git a/tools/quake3/common/inout.cpp b/tools/quake3/common/inout.cpp index 4caeda8e..80912835 100644 --- a/tools/quake3/common/inout.cpp +++ b/tools/quake3/common/inout.cpp @@ -27,8 +27,6 @@ // #include "cmdlib.h" -#include "mathlib.h" -#include "polylib.h" #include "inout.h" #include #include diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index 5f05e812..3340b214 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -448,8 +448,7 @@ void ProcessWorldModel( void ){ /* ydnar: fog hull */ if ( ENT_READKV( &value, &entities[ 0 ], "_foghull" ) ) { - char shader[MAX_QPATH]; - sprintf( shader, "textures/%s", value ); + const auto shader = String64()( "textures/", value ); MakeFogHullSurfs( e, tree, shader ); } diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index 31d5c2f3..ca1448e2 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -1085,8 +1085,6 @@ static void ParseRawBrush( bool onlyLights ){ vec_t shift[ 2 ]; vec_t rotate = 0; vec_t scale[ 2 ]; - char name[ MAX_QPATH ]; - char shader[ MAX_QPATH ]; int flags; @@ -1146,7 +1144,7 @@ static void ParseRawBrush( bool onlyLights ){ /* read shader name */ GetToken( false ); - strcpy( name, token ); + const auto shader = String64()( "textures/", token ); /* AP or 220? */ if ( g_brushType == BPRIMIT_UNDEFINED ){ @@ -1199,7 +1197,6 @@ static void ParseRawBrush( bool onlyLights ){ } /* set default flags and values */ - sprintf( shader, "textures/%s", name ); if ( onlyLights ) { si = &shaderInfo[ 0 ]; } diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 35147500..1a394b91 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -219,7 +219,6 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, const mapDrawSurface_t *ds; bspDrawVert_t *dv; const char *picoShaderName; - char shaderName[ MAX_QPATH ]; picoVec_t *xyz, *normal, *st; byte *color; picoIndex_t *indexes; @@ -385,12 +384,12 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, const /* shader renaming for sof2 */ if ( renameModelShaders ) { - strcpy( shaderName, picoShaderName ); + auto shaderName = String64()( PathExtensionless( picoShaderName ) ); if ( spawnFlags & 1 ) { - path_set_extension( shaderName, "_RMG_BSP" ); + shaderName << "_RMG_BSP"; } else{ - path_set_extension( shaderName, "_BSP" ); + shaderName << "_BSP"; } si = ShaderInfoForShader( shaderName ); } diff --git a/tools/quake3/q3map2/patch.cpp b/tools/quake3/q3map2/patch.cpp index 91aa90cb..ea3a6608 100644 --- a/tools/quake3/q3map2/patch.cpp +++ b/tools/quake3/q3map2/patch.cpp @@ -221,8 +221,6 @@ void ParsePatch( bool onlyLights ){ vec_t info[ 5 ]; int i, j, k; parseMesh_t *pm; - char texture[ MAX_QPATH ]; - char shader[ MAX_QPATH ]; mesh_t m; bspDrawVert_t *verts; epair_t *ep; @@ -233,9 +231,9 @@ void ParsePatch( bool onlyLights ){ MatchToken( "{" ); - /* get texture */ + /* get shader name */ GetToken( true ); - strcpy( texture, token ); + const auto shader = String64()( "textures/", token ); Parse1DMatrix( 5, info ); m.width = info[0]; @@ -355,7 +353,6 @@ void ParsePatch( bool onlyLights ){ pm->brushNum = entitySourceBrushes; /* set shader */ - sprintf( shader, "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); /* set mesh */ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 77616427..07081672 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1696,7 +1696,7 @@ mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec mapDrawSurface_t *DrawSurfaceForShader( const char *shader ); void ClipSidesIntoTree( entity_t *e, tree_t *tree ); void MakeDebugPortalSurfs( tree_t *tree ); -void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ); +void MakeFogHullSurfs( entity_t *e, tree_t *tree, const char *shader ); void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ); void AddEntitySurfaceModels( entity_t *e ); int AddSurfaceModels( mapDrawSurface_t *ds ); diff --git a/tools/quake3/q3map2/surface.cpp b/tools/quake3/q3map2/surface.cpp index bb81767b..cfc3b204 100644 --- a/tools/quake3/q3map2/surface.cpp +++ b/tools/quake3/q3map2/surface.cpp @@ -3046,7 +3046,7 @@ void MakeDebugPortalSurfs( tree_t *tree ){ generates drawsurfaces for a foghull (this MUST use a sky shader) */ -void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){ +void MakeFogHullSurfs( entity_t *e, tree_t *tree, const char *shader ){ shaderInfo_t *si; mapDrawSurface_t *ds; vec3_t fogMins, fogMaxs;