From 9c7637187666f258ac7d4e0e8112fa0ef04d2af0 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Tue, 8 Sep 2015 03:09:48 +0200 Subject: [PATCH] Modified ExtractFilePath, ExtractFileName, ExtractFileBase, ExtractFileExtension, strcpy -> Q_strncpyz --- contrib/bobtoolz/DBobView.cpp | 4 +- contrib/bobtoolz/DBrush.cpp | 4 +- contrib/bobtoolz/DEntity.cpp | 2 +- contrib/bobtoolz/DPatch.cpp | 4 +- contrib/bobtoolz/DShape.cpp | 8 +- contrib/bobtoolz/DTrainDrawer.cpp | 2 +- contrib/bobtoolz/DTreePlanter.cpp | 26 +- contrib/bobtoolz/dialogs/dialogs-gtk.cpp | 14 +- contrib/bobtoolz/funchandlers-GTK.cpp | 8 +- contrib/bobtoolz/misc.cpp | 4 +- contrib/bobtoolz/shapes.cpp | 2 +- contrib/camera/dialogs.cpp | 14 +- contrib/camera/funchandlers.cpp | 4 +- contrib/gtkgensurf/dec.cpp | 12 +- contrib/gtkgensurf/face.cpp | 6 +- contrib/gtkgensurf/gendlgs.cpp | 26 +- contrib/gtkgensurf/genmap.cpp | 90 +++---- contrib/gtkgensurf/gensurf.cpp | 30 +-- contrib/gtkgensurf/triangle.c | 118 +++++---- contrib/gtkgensurf/view.cpp | 6 +- contrib/prtview/ConfigDialog.cpp | 12 +- libs/cmdlib.h | 8 +- libs/cmdlib/cmdlib.cpp | 34 ++- libs/picomodel/lwo/pntspols.c | 3 +- libs/picomodel/picointernal.h | 6 + libs/picomodel/picomodel.c | 5 +- libs/picomodel/pm_3ds.c | 14 +- libs/picomodel/pm_ase.c | 5 +- libs/picomodel/pm_fm.c | 3 +- libs/picomodel/pm_lwo.c | 3 +- libs/picomodel/pm_md2.c | 10 +- libs/splines/math_vector.cpp | 2 +- libs/splines/splines.cpp | 6 +- plugins/eclassfgd/plugin.cpp | 12 +- plugins/map/parse.cpp | 10 +- plugins/mapxml/xmlwrite.cpp | 20 +- plugins/model/plugin.cpp | 2 +- plugins/shaders/shaders.cpp | 6 +- plugins/surface/surfacedialog.cpp | 12 +- plugins/surface_idtech2/surfacedialog.cpp | 12 +- plugins/surface_idtech2/surfaceflags.cpp | 2 +- plugins/vfspak/vfs.cpp | 4 +- plugins/vfspk3/vfs.cpp | 2 +- plugins/vfswad/vfs.cpp | 32 +-- plugins/vfswad/vfs.h | 2 +- radiant/brush.cpp | 2 +- radiant/dialog.cpp | 2 +- radiant/drag.cpp | 4 +- radiant/eclass.cpp | 4 +- radiant/eclass_def.cpp | 2 +- radiant/groupdialog.cpp | 2 +- radiant/gtkdlgs.cpp | 10 +- radiant/main.cpp | 8 +- radiant/mainframe.cpp | 10 +- radiant/map.cpp | 6 +- radiant/preferences.cpp | 22 +- radiant/profile.cpp | 4 +- radiant/qe3.cpp | 9 +- radiant/select.cpp | 2 +- radiant/targetname.cpp | 2 +- radiant/texwindow.cpp | 8 +- radiant/xywindow.cpp | 10 +- radiant/z.cpp | 2 +- tools/quake3/common/cmdlib.c | 28 +- tools/quake3/common/cmdlib.h | 6 +- tools/quake3/common/inout.c | 8 +- tools/quake3/q3data/3dslib.c | 22 +- tools/quake3/q3data/models.c | 4 +- tools/quake3/q3data/video.c | 4 +- tools/quake3/q3map2/bsp.c | 4 +- tools/quake3/q3map2/bspfile_ibsp.c | 2 +- tools/quake3/q3map2/bspfile_rbsp.c | 2 +- tools/quake3/q3map2/convert_ase.c | 10 +- tools/quake3/q3map2/convert_map.c | 8 +- tools/quake3/q3map2/exportents.c | 6 +- tools/quake3/q3map2/image.c | 14 +- tools/quake3/q3map2/light.c | 4 +- tools/quake3/q3map2/light_bounce.c | 6 +- tools/quake3/q3map2/light_trace.c | 4 +- tools/quake3/q3map2/lightmaps_ydnar.c | 18 +- tools/quake3/q3map2/main.c | 20 +- tools/quake3/q3map2/map.c | 10 +- tools/quake3/q3map2/model.c | 10 +- tools/quake3/q3map2/patch.c | 2 +- tools/quake3/q3map2/path_init.c | 2 +- tools/quake3/q3map2/shaders.c | 44 +-- tools/quake3/q3map2/surface_extra.c | 8 +- tools/quake3/q3map2/writebsp.c | 12 +- tools/urt/tools/quake3/q3map2/bsp.c | 6 +- .../tools/quake3/q3map2/bspfile_abstract.c | 10 +- tools/urt/tools/quake3/q3map2/bspfile_ibsp.c | 2 +- tools/urt/tools/quake3/q3map2/bspfile_rbsp.c | 2 +- tools/urt/tools/quake3/q3map2/convert_ase.c | 4 +- tools/urt/tools/quake3/q3map2/convert_map.c | 8 +- tools/urt/tools/quake3/q3map2/exportents.c | 6 +- tools/urt/tools/quake3/q3map2/image.c | 14 +- tools/urt/tools/quake3/q3map2/light.c | 6 +- tools/urt/tools/quake3/q3map2/light_bounce.c | 6 +- tools/urt/tools/quake3/q3map2/light_trace.c | 4 +- .../urt/tools/quake3/q3map2/lightmaps_ydnar.c | 10 +- tools/urt/tools/quake3/q3map2/main.c | 14 +- tools/urt/tools/quake3/q3map2/map.c | 8 +- tools/urt/tools/quake3/q3map2/model.c | 10 +- tools/urt/tools/quake3/q3map2/patch.c | 2 +- tools/urt/tools/quake3/q3map2/path_init.c | 12 +- tools/urt/tools/quake3/q3map2/shaders.c | 250 +++++++++--------- tools/urt/tools/quake3/q3map2/surface_extra.c | 8 +- tools/urt/tools/quake3/q3map2/writebsp.c | 12 +- 108 files changed, 701 insertions(+), 671 deletions(-) diff --git a/contrib/bobtoolz/DBobView.cpp b/contrib/bobtoolz/DBobView.cpp index f10833e4..1eceeab8 100644 --- a/contrib/bobtoolz/DBobView.cpp +++ b/contrib/bobtoolz/DBobView.cpp @@ -313,8 +313,8 @@ bool DBobView::CalculateTrajectory( vec3_t start, vec3_t apex, float multiplier, } void DBobView::Begin( const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra ){ - strcpy( entTrigger, trigger ); - strcpy( entTarget, target ); + Q_strncpyz( entTrigger, trigger, sizeof( entTrigger ) ); + Q_strncpyz( entTarget, target, sizeof( entTarget ) ); fMultiplier = multiplier; fVarGravity = varGravity; diff --git a/contrib/bobtoolz/DBrush.cpp b/contrib/bobtoolz/DBrush.cpp index a11908bf..f6579add 100644 --- a/contrib/bobtoolz/DBrush.cpp +++ b/contrib/bobtoolz/DBrush.cpp @@ -727,7 +727,7 @@ bool DBrush::ResetTextures( const char* textureName, float fScale[2], float f { if ( !strcmp( ( *resetPlane )->texInfo.m_TextureName, textureName ) ) { if ( bResetTextureName ) { - strcpy( ( *resetPlane )->texInfo.m_TextureName, newTextureName ); + Q_strncpyz( ( *resetPlane )->texInfo.m_TextureName, newTextureName, sizeof( ( *resetPlane )->texInfo.m_TextureName ) ); } if ( bResetScale[0] ) { @@ -758,7 +758,7 @@ bool DBrush::ResetTextures( const char* textureName, float fScale[2], float f for ( list::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ ) { if ( bResetTextureName ) { - strcpy( ( *resetPlane )->texInfo.m_TextureName, newTextureName ); + Q_strncpyz( ( *resetPlane )->texInfo.m_TextureName, newTextureName, sizeof( ( *resetPlane )->texInfo.m_TextureName ) ); } if ( bResetScale[0] ) { diff --git a/contrib/bobtoolz/DEntity.cpp b/contrib/bobtoolz/DEntity.cpp index 3320da80..bb7bffb8 100644 --- a/contrib/bobtoolz/DEntity.cpp +++ b/contrib/bobtoolz/DEntity.cpp @@ -120,7 +120,7 @@ char* getNextBracket( char* s ){ bool DEntity::LoadFromPrt( char *filename ){ CPortals portals; - strcpy( portals.fn, filename ); + Q_strncpyz( portals.fn, filename, sizeof( portals.fn ) ); portals.Load(); if ( portals.node_count == 0 ) { diff --git a/contrib/bobtoolz/DPatch.cpp b/contrib/bobtoolz/DPatch.cpp index aa0d52b7..25cf9a09 100644 --- a/contrib/bobtoolz/DPatch.cpp +++ b/contrib/bobtoolz/DPatch.cpp @@ -48,7 +48,7 @@ DPatch::~DPatch(){ } void DPatch::SetTexture( const char *textureName ){ - strcpy( texture, textureName ); + Q_strncpyz( texture, textureName, sizeof( texture ) ); } void CopyDrawVert( const drawVert_t* in, drawVert_t* out ){ @@ -124,7 +124,7 @@ void DPatch::RemoveFromRadiant(){ bool DPatch::ResetTextures( const char *oldTextureName, const char *newTextureName ){ if ( !oldTextureName || !strcmp( texture, oldTextureName ) ) { - strcpy( texture, newTextureName ); + Q_strncpyz( texture, newTextureName, sizeof( texture ) ); return TRUE; } diff --git a/contrib/bobtoolz/DShape.cpp b/contrib/bobtoolz/DShape.cpp index 34a586c3..4ffa426b 100644 --- a/contrib/bobtoolz/DShape.cpp +++ b/contrib/bobtoolz/DShape.cpp @@ -367,7 +367,7 @@ bool DShape::BuildPit( vec3_t min, vec3_t max ){ int team = ( rand() % 10000 ) + 5000; // ************* SPEAKER *************** - sprintf( buffer, "t%i_1", team ); + snprintf( buffer, sizeof( buffer ), "t%i_1", team ); // trigger for speaker vec3_t triggerVoiceBtm; @@ -388,7 +388,7 @@ bool DShape::BuildPit( vec3_t min, vec3_t max ){ DEntity* targetVoice = m_Container.AddEntity( "target_speaker" ); targetVoice->AddEPair( "targetname", buffer ); - sprintf( buffer, "%f %f %f", voiceOrigin[0], voiceOrigin[1], voiceOrigin[2] ); + snprintf( buffer, sizeof( buffer ), "%f %f %f", voiceOrigin[0], voiceOrigin[1], voiceOrigin[2] ); targetVoice->AddEPair( "origin", buffer ); targetVoice->AddEPair( "spawnflags", "8" ); targetVoice->AddEPair( "noise", "*falling1.wav" ); @@ -397,7 +397,7 @@ bool DShape::BuildPit( vec3_t min, vec3_t max ){ // *********** END SPEAKER ************* // ********* POWERUP REMOVAL *********** - sprintf( buffer, "t%i_2", team ); + snprintf( buffer, sizeof( buffer ), "t%i_2", team ); // trigger for powerup removal vec3_t triggerPwrRmvTop, triggerPwrRmvBtm; @@ -420,7 +420,7 @@ bool DShape::BuildPit( vec3_t min, vec3_t max ){ DEntity* targetPwrRmv = m_Container.AddEntity( "target_remove_powerups" ); targetPwrRmv->AddEPair( "targetname", buffer ); - sprintf( buffer, "%f %f %f", pwrRmvOrigin[0], pwrRmvOrigin[1], pwrRmvOrigin[2] ); + snprintf( buffer, sizeof( buffer ), "%f %f %f", pwrRmvOrigin[0], pwrRmvOrigin[1], pwrRmvOrigin[2] ); targetPwrRmv->AddEPair( "origin", buffer ); //-------------------- diff --git a/contrib/bobtoolz/DTrainDrawer.cpp b/contrib/bobtoolz/DTrainDrawer.cpp index da38ffba..3ffbf274 100644 --- a/contrib/bobtoolz/DTrainDrawer.cpp +++ b/contrib/bobtoolz/DTrainDrawer.cpp @@ -236,7 +236,7 @@ void DTrainDrawer::BuildPaths() { for ( int j = 2;; j++ ) { char buffer[32]; - sprintf( buffer, "control%i", j ); + snprintf( buffer, sizeof( buffer ), "control%i", j ); e.SpawnString( buffer, NULL, &control ); if ( !control ) { diff --git a/contrib/bobtoolz/DTreePlanter.cpp b/contrib/bobtoolz/DTreePlanter.cpp index 78f0e52e..21ff04c4 100644 --- a/contrib/bobtoolz/DTreePlanter.cpp +++ b/contrib/bobtoolz/DTreePlanter.cpp @@ -47,7 +47,7 @@ bool DTreePlanter::OnLButtonDown( guint32 nFlags, gdouble x, gdouble y ) { char buffer[128]; DEntity e( m_entType ); - sprintf( buffer, "%i %i %i", (int)vhit[0], (int)vhit[1], (int)vhit[2] ); + snprintf( buffer, sizeof( buffer ), "%i %i %i", (int)vhit[0], (int)vhit[1], (int)vhit[2] ); e.AddEPair( "origin", buffer ); if ( m_autoLink ) { @@ -56,7 +56,7 @@ bool DTreePlanter::OnLButtonDown( guint32 nFlags, gdouble x, gdouble y ) { int entNum = -1, lastEntNum = -1, entpos; for ( int i = 0; i < 256; i++ ) { - sprintf( buffer, m_linkName, i ); + snprintf( buffer, sizeof( buffer ), m_linkName, i ); pThisEntity = FindEntityFromTargetname( buffer, &entNum ); if ( pThisEntity ) { @@ -67,10 +67,10 @@ bool DTreePlanter::OnLButtonDown( guint32 nFlags, gdouble x, gdouble y ) { } if ( !pLastEntity ) { - sprintf( buffer, m_linkName, 0 ); + snprintf( buffer, sizeof( buffer ), m_linkName, 0 ); } else { - sprintf( buffer, m_linkName, entpos + 1 ); + snprintf( buffer, sizeof( buffer ), m_linkName, entpos + 1 ); } e.AddEPair( "targetname", buffer ); @@ -88,7 +88,7 @@ bool DTreePlanter::OnLButtonDown( guint32 nFlags, gdouble x, gdouble y ) { int angleYaw = ( rand() % ( m_maxYaw - m_minYaw + 1 ) ) + m_minYaw; int anglePitch = ( rand() % ( m_maxPitch - m_minPitch + 1 ) ) + m_minPitch; - sprintf( buffer, "%i %i 0", anglePitch, angleYaw ); + snprintf( buffer, sizeof( buffer ), "%i %i 0", anglePitch, angleYaw ); e.AddEPair( "angles", buffer ); } @@ -100,7 +100,7 @@ bool DTreePlanter::OnLButtonDown( guint32 nFlags, gdouble x, gdouble y ) { if ( m_useScale ) { float scale = ( ( ( rand() % 1000 ) * 0.001f ) * ( m_maxScale - m_minScale ) ) + m_minScale; - sprintf( buffer, "%f", scale ); + snprintf( buffer, sizeof( buffer ), "%f", scale ); e.AddEPair( "modelscale", buffer ); } @@ -205,7 +205,7 @@ void DTreePlanter::DropEntsToGround( void ) { FindDropPoint( vec, out ); char buffer[256]; - sprintf( buffer, "%f %f %f", out[0], out[1], out[2] ); + snprintf( buffer, sizeof( buffer ), "%f %f %f", out[0], out[1], out[2] ); ent.AddEPair( "origin", buffer ); ent.RemoveFromRadiant(); ent.BuildInRadiant( FALSE ); @@ -221,17 +221,17 @@ void DTreePlanter::MakeChain( void ) { for ( i = 0; i < m_linkNum; i++ ) { DEntity e( "info_train_spline_main" ); - sprintf( buffer, "%s_pt%i", m_linkName, i ); + snprintf( buffer, sizeof( buffer ), "%s_pt%i", m_linkName, i ); e.AddEPair( "targetname", buffer ); - sprintf( buffer, "0 %i 0", i * 64 ); + snprintf( buffer, sizeof( buffer ), "0 %i 0", i * 64 ); e.AddEPair( "origin", buffer ); if ( i != m_linkNum - 1 ) { - sprintf( buffer, "%s_pt%i", m_linkName, i + 1 ); + snprintf( buffer, sizeof( buffer ), "%s_pt%i", m_linkName, i + 1 ); e.AddEPair( "target", buffer ); - sprintf( buffer, "%s_ctl%i", m_linkName, i ); + snprintf( buffer, sizeof( buffer ), "%s_ctl%i", m_linkName, i ); e.AddEPair( "control", buffer ); } @@ -241,10 +241,10 @@ void DTreePlanter::MakeChain( void ) { for ( i = 0; i < m_linkNum - 1; i++ ) { DEntity e( "info_train_spline_control" ); - sprintf( buffer, "%s_ctl%i", m_linkName, i ); + snprintf( buffer, sizeof( buffer ), "%s_ctl%i", m_linkName, i ); e.AddEPair( "targetname", buffer ); - sprintf( buffer, "0 %i 0", ( i * 64 ) + 32 ); + snprintf( buffer, sizeof( buffer ), "0 %i 0", ( i * 64 ) + 32 ); e.AddEPair( "origin", buffer ); e.BuildInRadiant( FALSE ); diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp index cb3248b7..cf9e445f 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp @@ -132,7 +132,7 @@ bool ValidateTextFloat( const char* pData, const char* error_title, float* value bool ValidateTextFloatRange( const char* pData, float min, float max, const char* error_title, float* value ){ char error_buffer[256]; - sprintf( error_buffer, "Please Enter A Floating Point Number Between %.3f and %.3f", min, max ); + snprintf( error_buffer, sizeof( error_buffer ), "Please Enter A Floating Point Number Between %.3f and %.3f", min, max ); if ( pData ) { float testNum = (float)atof( pData ); @@ -757,8 +757,8 @@ int DoBuildStairsBox( BuildStairsRS* rs ){ if ( ret == IDOK ) { rs->bUseDetail = gtk_toggle_button_get_active( (GtkToggleButton*)checkUseDetail ) ? true : false; - strcpy( rs->riserTexture, gtk_entry_get_text( (GtkEntry*)textRiserTex ) ); - strcpy( rs->mainTexture, gtk_entry_get_text( (GtkEntry*)textMainTex ) ); + Q_strncpyz( rs->riserTexture, gtk_entry_get_text( (GtkEntry*)textRiserTex ), sizeof( rs->riserTexture ) ); + Q_strncpyz( rs->mainTexture, gtk_entry_get_text( (GtkEntry*)textMainTex ), sizeof( rs->mainTexture ) ); if ( gtk_toggle_button_get_active( (GtkToggleButton*)radioNorth ) ) { rs->direction = MOVE_NORTH; @@ -1005,8 +1005,8 @@ int DoDoorsBox( DoorRS* rs ){ while ( loop ) gtk_main_iteration(); - strcpy( rs->mainTexture, gtk_entry_get_text( GTK_ENTRY( textFrontBackTex ) ) ); - strcpy( rs->trimTexture, gtk_entry_get_text( GTK_ENTRY( textTrimTex ) ) ); + Q_strncpyz( rs->mainTexture, gtk_entry_get_text( GTK_ENTRY( textFrontBackTex ) ), sizeof( rs->mainTexture ) ); + Q_strncpyz( rs->trimTexture, gtk_entry_get_text( GTK_ENTRY( textTrimTex ) ), sizeof( rs->trimTexture ) ); rs->bScaleMainH = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( checkScaleMainH ) ) ? true : false; rs->bScaleMainV = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( checkScaleMainV ) ) ? true : false; @@ -1574,8 +1574,8 @@ int DoResetTextureBox( ResetTextureRS* rs ){ rs->bResetTextureName = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( dlgTexReset.cbTexChange ) ); if ( rs->bResetTextureName ) { - strcpy( rs->textureName, gtk_entry_get_text( GTK_ENTRY( dlgTexReset.editTexOld ) ) ); - strcpy( rs->newTextureName, gtk_entry_get_text( GTK_ENTRY( dlgTexReset.editTexNew ) ) ); + Q_strncpyz( rs->textureName, gtk_entry_get_text( GTK_ENTRY( dlgTexReset.editTexOld ) ), sizeof( rs->textureName ) ); + Q_strncpyz( rs->newTextureName, gtk_entry_get_text( GTK_ENTRY( dlgTexReset.editTexNew ) ), sizeof( rs->newTextureName ) ); } } } diff --git a/contrib/bobtoolz/funchandlers-GTK.cpp b/contrib/bobtoolz/funchandlers-GTK.cpp index 2815b99d..9a8ff62c 100644 --- a/contrib/bobtoolz/funchandlers-GTK.cpp +++ b/contrib/bobtoolz/funchandlers-GTK.cpp @@ -186,7 +186,7 @@ void DoResetTextures(){ else { texName = GetCurrentTexture(); - strcpy( rs.textureName, GetCurrentTexture() ); + Q_strncpyz( rs.textureName, GetCurrentTexture(), sizeof( rs.textureName ) ); } int ret; @@ -216,7 +216,7 @@ void DoResetTextures(){ void DoBuildStairs( vec3_t vMin, vec3_t vMax ){ BuildStairsRS rs; - strcpy( rs.mainTexture, GetCurrentTexture() ); + Q_strncpyz( rs.mainTexture, GetCurrentTexture(), sizeof( rs.mainTexture ) ); // ensure we have something selected if ( g_FuncTable.m_pfnSelectedBrushCount() != 1 ) { @@ -319,7 +319,7 @@ void DoBuildDoors( vec3_t vMin, vec3_t vMax ){ // cant release until we delete the brush, if we do... DoorRS rs; - strcpy( rs.mainTexture, GetCurrentTexture() ); + Q_strncpyz( rs.mainTexture, GetCurrentTexture(), sizeof( rs.mainTexture ) ); if ( DoDoorsBox( &rs ) == IDOK ) { g_FuncTable.m_pfnDeleteBrushHandle( brush ); @@ -554,7 +554,7 @@ void DoVisAnalyse(){ return; } - strcpy( filename, rad_filename ); + Q_strncpyz( filename, rad_filename, sizeof( filename ) ); char* ext = strrchr( filename, '.' ) + 1; strcpy( ext, "bsp" ); // rename the extension diff --git a/contrib/bobtoolz/misc.cpp b/contrib/bobtoolz/misc.cpp index 111936ea..9e6a3d71 100644 --- a/contrib/bobtoolz/misc.cpp +++ b/contrib/bobtoolz/misc.cpp @@ -39,7 +39,7 @@ char g_CurrentTexture[256] = ""; void ReadCurrentTexture(){ const char* textureName = g_FuncTable.m_pfnGetCurrentTexture(); - strcpy( g_CurrentTexture, textureName ); + Q_strncpyz( g_CurrentTexture, textureName, sizeof( g_CurrentTexture ) ); } const char* GetCurrentTexture(){ @@ -354,7 +354,7 @@ void FillDefaultTexture( _QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc faceData->m_nFlags = 0; faceData->m_nValue = 0; if ( *texture ) { - strcpy( faceData->m_TextureName, texture ); + Q_strncpyz( faceData->m_TextureName, texture, sizeof( faceData->m_TextureName ) ); } else{ strcpy( faceData->m_TextureName, "textures/common/caulk" ); diff --git a/contrib/bobtoolz/shapes.cpp b/contrib/bobtoolz/shapes.cpp index 6609058e..18c46191 100644 --- a/contrib/bobtoolz/shapes.cpp +++ b/contrib/bobtoolz/shapes.cpp @@ -574,7 +574,7 @@ void BuildDoorsX2( vec3_t min, vec3_t max, srand( (unsigned)time( NULL ) ); char teamname[256]; - sprintf( teamname, "t%i", rand() ); + snprintf( teamname, sizeof( teamname ), "t%i", rand() ); /*epair_t* epDoor13 = */ GetNextChainItem( epDoor12, "team", teamname ); /*epair_t* epDoor23 = */ GetNextChainItem( epDoor22, "team", teamname ); diff --git a/contrib/camera/dialogs.cpp b/contrib/camera/dialogs.cpp index c8dd4cf1..1db0a84a 100644 --- a/contrib/camera/dialogs.cpp +++ b/contrib/camera/dialogs.cpp @@ -194,10 +194,10 @@ static gint ci_apply( GtkWidget *widget, gpointer data ){ GetCurrentCam()->GetCam()->buildCamera(); } - sprintf( buf, "%.2f", GetCurrentCam()->GetCam()->getBaseTime() ); + snprintf( buf, sizeof( buf ), "%.2f", GetCurrentCam()->GetCam()->getBaseTime() ); gtk_entry_set_text( GTK_ENTRY( g_pSecondsEntry ), buf ); - sprintf( buf, "%.2f", GetCurrentCam()->GetCam()->getTotalTime() ); + snprintf( buf, sizeof( buf ), "%.2f", GetCurrentCam()->GetCam()->getTotalTime() ); gtk_label_set_text( g_pCurrentTime, "0.00" ); gtk_label_set_text( g_pTotalTime, buf ); @@ -326,7 +326,7 @@ static void RefreshEventList( void ){ } // Total duration might have changed - sprintf( buf, "%.2f", GetCurrentCam()->GetCam()->getTotalTime() ); + snprintf( buf, sizeof( buf ), "%.2f", GetCurrentCam()->GetCam()->getTotalTime() ); gtk_label_set_text( g_pCurrentTime, "0.00" ); gtk_label_set_text( g_pTotalTime, buf ); @@ -462,7 +462,7 @@ static void ci_add_target( GtkButton *button, gpointer data ){ gtk_box_pack_start( GTK_BOX( hbox ), name, TRUE, TRUE, 0 ); gtk_widget_show( name ); - sprintf( buf, "target%i", GetCurrentCam()->GetCam()->numTargets() + 1 ); + snprintf( buf, sizeof( buf ), "target%i", GetCurrentCam()->GetCam()->numTargets() + 1 ); gtk_entry_set_text( GTK_ENTRY( name ), buf ); // -------------------------- // @@ -650,10 +650,10 @@ static gint ci_camlist_changed( GtkWidget *widget, gpointer data ){ gtk_label_set_text( g_pCamType, GetCurrentCam()->GetCam()->getPositionObj()->typeStr() ); // Set duration - sprintf( buf, "%.2f", GetCurrentCam()->GetCam()->getBaseTime() ); + snprintf( buf, sizeof( buf ), "%.2f", GetCurrentCam()->GetCam()->getBaseTime() ); gtk_entry_set_text( GTK_ENTRY( g_pSecondsEntry ), buf ); - sprintf( buf, "%.2f", GetCurrentCam()->GetCam()->getTotalTime() ); + snprintf( buf, sizeof( buf ), "%.2f", GetCurrentCam()->GetCam()->getTotalTime() ); gtk_label_set_text( g_pCurrentTime, "0.00" ); gtk_label_set_text( g_pTotalTime, buf ); @@ -885,7 +885,7 @@ static gint ci_del( GtkWidget *widget, gpointer data ){ static gint ci_timeline_changed( GtkAdjustment *adjustment ){ char buf[128]; - sprintf( buf, "%.2f", gtk_adjustment_get_value( adjustment ) / 1000.f ); + snprintf( buf, sizeof( buf ), "%.2f", gtk_adjustment_get_value( adjustment ) / 1000.f ); gtk_label_set_text( g_pCurrentTime, buf ); // FIXME: this will never work completely perfect. Startcamera calls buildcamera, which sets all events to 'nottriggered'. diff --git a/contrib/camera/funchandlers.cpp b/contrib/camera/funchandlers.cpp index 337c8945..adce36f9 100644 --- a/contrib/camera/funchandlers.cpp +++ b/contrib/camera/funchandlers.cpp @@ -41,13 +41,13 @@ static void DoNewCamera( idCameraPosition::positionType type ){ if ( cam ) { char buf[128]; - sprintf( buf, "camera%i", cam->GetCamNum() ); + snprintf( buf, sizeof( buf ), "camera%i", cam->GetCamNum() ); cam->GetCam()->startNewCamera( type ); cam->GetCam()->setName( buf ); cam->GetCam()->buildCamera(); - sprintf( buf, "Unsaved Camera %i", cam->GetCamNum() ); + snprintf( buf, sizeof( buf ), "Unsaved Camera %i", cam->GetCamNum() ); cam->SetFileName( buf, false ); SetCurrentCam( cam ); diff --git a/contrib/gtkgensurf/dec.cpp b/contrib/gtkgensurf/dec.cpp index 09a16993..c65ada23 100644 --- a/contrib/gtkgensurf/dec.cpp +++ b/contrib/gtkgensurf/dec.cpp @@ -1015,8 +1015,8 @@ void MakeBrushes( int NumTris, NODE *Node, TRI *Tri,bool surf, for ( j = 0; j < 5; j++ ) { - strcpy( brush.face[j].texture, - ( strlen( texture1 ) ? texture1 : texture0 ) ); + Q_strncpyz( brush.face[j].texture, + ( strlen( texture1 ) ? texture1 : texture0 ), sizeof( brush.face[j].texture ) ); brush.face[j].Shift[0] = (float)TexOffset[0]; brush.face[j].Shift[1] = (float)TexOffset[1]; brush.face[j].Rotate = 0.; @@ -1038,14 +1038,14 @@ void MakeBrushes( int NumTris, NODE *Node, TRI *Tri,bool surf, CrossProduct( t[0],t[1],SurfNormal ); VectorNormalize( SurfNormal,SurfNormal ); if ( DotProduct( SurfNormal,PlaneNormal ) < Steep ) { - strcpy( brush.face[0].texture,texture2 ); + Q_strncpyz( brush.face[0].texture, texture2, sizeof( brush.face[0].texture ) ); } else{ - strcpy( brush.face[0].texture,texture0 ); + Q_strncpyz( brush.face[0].texture, texture0, sizeof( brush.face[0].texture ) ); } } else{ - strcpy( brush.face[0].texture,texture0 ); + Q_strncpyz( brush.face[0].texture, texture0, sizeof( brush.face[0].texture ) ); } if ( surf ) { @@ -1364,7 +1364,7 @@ void MapOut( int NumNodes,int NumTris, NODE *Node, TRI *Tri ){ } // switch (Plane) for ( face = 0; face < 6; face++ ) { - strcpy( brush.face[face].texture,( face <= 1 ? skip : hint ) ); + Q_strncpyz( brush.face[face].texture,( face <= 1 ? skip : hint ), sizeof( brush.face[face].texture ) ); brush.face[face].Shift[0] = 0; brush.face[face].Shift[1] = 0; brush.face[face].Rotate = 0.; diff --git a/contrib/gtkgensurf/face.cpp b/contrib/gtkgensurf/face.cpp index 8151dfe8..4937f8f4 100644 --- a/contrib/gtkgensurf/face.cpp +++ b/contrib/gtkgensurf/face.cpp @@ -359,7 +359,7 @@ void UseFaceBounds(){ BestDot = Dot; BestFace = i; if ( strlen( QERFaceData->m_TextureName ) ) { - strcpy( Texture[Game][0],QERFaceData->m_TextureName ); + Q_strncpyz( Texture[Game][0], QERFaceData->m_TextureName, sizeof( Texture[Game][0] ) ); } } } @@ -370,8 +370,8 @@ void UseFaceBounds(){ } QERFaceData = g_FuncTable.m_pfnGetFaceData( vp,i ); if ( strlen( QERFaceData->m_TextureName ) ) { - if ( strcmp( Texture[Game][0],QERFaceData->m_TextureName ) ) { - strcpy( Texture[Game][1],QERFaceData->m_TextureName ); + if ( strcmp( Texture[Game][0], QERFaceData->m_TextureName ) ) { + Q_strncpyz( Texture[Game][1], QERFaceData->m_TextureName, sizeof( Texture[Game][1] ) ); } } } diff --git a/contrib/gtkgensurf/gendlgs.cpp b/contrib/gtkgensurf/gendlgs.cpp index 0bf7ea7a..6736f4f9 100644 --- a/contrib/gtkgensurf/gendlgs.cpp +++ b/contrib/gtkgensurf/gendlgs.cpp @@ -726,14 +726,14 @@ static void main_go( GtkWidget *widget, gpointer data ){ ReadDlgValues( current_tab ); if ( NH < 1 || NH > MAX_ROWS ) { - sprintf( Text, _( "The number of divisions must be > 0 and no greater than %d." ), MAX_ROWS ); + snprintf( Text, sizeof( Text ), _( "The number of divisions must be > 0 and no greater than %d." ), MAX_ROWS ); g_FuncTable.m_pfnMessageBox( g_pWnd, Text, "GenSurf", MB_ICONEXCLAMATION, NULL ); gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), EXTENTS_TAB ); return; } if ( NV < 1 || NV > MAX_ROWS ) { - sprintf( Text, _( "The number of divisions must be > 0 and no greater than %d." ), MAX_ROWS ); + snprintf( Text, sizeof( Text ), _( "The number of divisions must be > 0 and no greater than %d." ), MAX_ROWS ); g_FuncTable.m_pfnMessageBox( g_pWnd, Text, "GenSurf", MB_ICONEXCLAMATION, NULL ); gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), EXTENTS_TAB ); return; @@ -882,9 +882,9 @@ static void extents_snaptogrid_spin( GtkAdjustment *adj, int *data ){ static gint bitmap_file_entryfocusout( GtkWidget* widget, GdkEventFocus* event, gpointer data ){ char filename[NAME_MAX]; - strcpy( filename, gtk_entry_get_text( GTK_ENTRY( widget ) ) ); + Q_strncpyz( filename, gtk_entry_get_text( GTK_ENTRY( widget ) ), sizeof( filename ) ); if ( strcmp( filename,gbmp.name ) ) { - strcpy( gbmp.name,filename ); + Q_strncpyz( gbmp.name, filename, sizeof( gbmp.name ) ); if ( strlen( gbmp.name ) ) { OpenBitmap(); } @@ -900,12 +900,12 @@ static void bitmap_browse( GtkWidget *widget, gpointer data ){ filename = g_FuncTable.m_pfnFileDialog( g_pWnd, TRUE, "Bitmap File", gbmp.defpath, "gtkgensurf", NULL ); if ( filename != NULL ) { - strcpy( gbmp.name, filename ); + Q_strncpyz( gbmp.name, filename, sizeof( gbmp.name ) ); ptr = (char *) strrchr( filename, G_DIR_SEPARATOR ); if ( ptr != NULL ) { *( ptr + 1 ) = '\0'; - strcpy( gbmp.defpath, filename ); + Q_strncpyz( gbmp.defpath, filename, sizeof( gbmp.defpath ) ); } OpenBitmap(); @@ -914,7 +914,7 @@ static void bitmap_browse( GtkWidget *widget, gpointer data ){ } static void bitmap_reload( GtkWidget *widget, gpointer data ){ - strcpy( gbmp.name, gtk_entry_get_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "bmp_file" ) ) ) ); + Q_strncpyz( gbmp.name, gtk_entry_get_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "bmp_file" ) ) ), sizeof( gbmp.name ) ); if ( strlen( gbmp.name ) ) { OpenBitmap(); ENABLE_WIDGET( "go", ( gbmp.colors != NULL ? TRUE : FALSE ) ); @@ -935,7 +935,7 @@ static gint fix_value_entryfocusout( GtkWidget* widget, GdkEventFocus *event, gp gdk_beep(); g_FuncTable.m_pfnMessageBox( g_pWnd, "The value must be between -65536 and 65536, inclusive.", "GenSurf", MB_OK | MB_ICONEXCLAMATION, NULL ); - sprintf( Text, "%d", (int)xyz[Vertex[0].i][Vertex[0].j].fixed_value ); + snprintf( Text, sizeof( Text ), "%d", (int)xyz[Vertex[0].i][Vertex[0].j].fixed_value ); gtk_entry_set_text( GTK_ENTRY( widget ), Text ); gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( widget ) ), widget ); } @@ -1031,7 +1031,7 @@ void vertex_selected(){ gtk_spin_button_set_value( GTK_SPIN_BUTTON( g_object_get_data( G_OBJECT( g_pWnd ), "fix_value" ) ), (int)xyz[Vertex[0].i][Vertex[0].j].fixed_value ); - sprintf( Text, "%d", (int)xyz[Vertex[0].i][Vertex[0].j].range ); + snprintf( Text, sizeof( Text ), "%d", (int)xyz[Vertex[0].i][Vertex[0].j].range ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "fix_range" ) ), Text ); snprintf( Text, sizeof( Text ), "%.5g", xyz[Vertex[0].i][Vertex[0].j].rate ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "fix_rate" ) ), Text ); @@ -1070,7 +1070,7 @@ static void texture_terrainent( GtkToggleButton *check, gpointer data ){ } static void texture_set( int index, const char* name ){ - strcpy( Texture[Game][index], name ); + Q_strncpyz( Texture[Game][index], name, sizeof( Texture[Game][index] ) ); } static gint texture_entryfocusout( GtkWidget* widget, GdkEventFocus* event, gpointer data ){ @@ -2132,8 +2132,8 @@ qboolean CALLBACK AboutDlgProc( HWND hwnd, unsigned msg, UINT wparam, LONG lpara switch ( msg ) { case WM_INITDIALOG: - strcpy( szText,"About " ); - strcat( szText,gszCaption ); + Q_strncpyz( szText, "About ", sizeof( szText ) ); + strncat( szText, gszCaption, sizeof( szText ) ); SetWindowText( hwnd,gszCaption ); SetDlgItemText( hwnd,DLG_ABOUT_APP,szText ); /* Application icon: */ @@ -2217,7 +2217,7 @@ qboolean CALLBACK AboutDlgProc( HWND hwnd, unsigned msg, UINT wparam, LONG lpara void About(){ if ( DialogBox( ghInst,"About", ghwnd_main, (DLGPROC)AboutDlgProc ) < 0 ) { char Text[256]; - sprintf( Text,"In About(), GetLastError()=0x%08x",GetLastError() ); + snprintf( Text, sizeof( Text ),"In About(), GetLastError()=0x%08x",GetLastError() ); MessageBox( ghwnd_main,Text,"GenSurf",MB_ICONEXCLAMATION ); } } diff --git a/contrib/gtkgensurf/genmap.cpp b/contrib/gtkgensurf/genmap.cpp index 7de00c4f..b0c934b0 100644 --- a/contrib/gtkgensurf/genmap.cpp +++ b/contrib/gtkgensurf/genmap.cpp @@ -192,7 +192,7 @@ int MapPatches(){ NH_patch -= 2; NH_remain -= ( NH_patch - 1 ); if ( NH_remain < 0 ) { - sprintf( szOops, "Oops... screwed up with NH=%d", NH ); + snprintf( szOops, sizeof( szOops ), "Oops... screwed up with NH=%d", NH ); g_FuncTable.m_pfnMessageBox( NULL, szOops, "Uh oh", 0, NULL ); } NV_remain = NV + 1; @@ -233,7 +233,7 @@ int MapPatches(){ NV_patch -= 2; NV_remain -= ( NV_patch - 1 ); if ( NV_remain < 0 ) { - sprintf( szOops, "Oops... screwed up with NV=%d", NV ); + snprintf( szOops, sizeof( szOops ), "Oops... screwed up with NV=%d", NV ); g_FuncTable.m_pfnMessageBox( NULL, szOops, "Uh oh", 0, NULL ); } @@ -287,9 +287,9 @@ void MapBrushes(){ BRUSH brush; XYZ v[8]; - strcpy( surftext,Texture[Game][0] ); - strcpy( sidetext,( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); - strcpy( surftext2,( strlen( Texture[Game][2] ) ? Texture[Game][2] : Texture[Game][0] ) ); + Q_strncpyz( surftext, Texture[Game][0], sizeof( surftext ) ); + Q_strncpyz( sidetext,( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( sidetext ) ); + Q_strncpyz( surftext2,( strlen( Texture[Game][2] ) ? Texture[Game][2] : Texture[Game][0] ), sizeof( surftext2 ) ); // if surftext2 is identical to surftext, there's no need to // check surface angle @@ -376,8 +376,8 @@ void MapBrushes(){ XYZtoV( &v[0],&brush.face[0].v[0] ); XYZtoV( &v[3],&brush.face[0].v[1] ); XYZtoV( &v[4],&brush.face[0].v[2] ); - strcpy( brush.face[0].texture, - ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); + Q_strncpyz( brush.face[0].texture, + ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( brush.face[0].texture ) ); brush.face[0].Shift[0] = (float)TexOffset[0]; brush.face[0].Shift[1] = (float)TexOffset[1]; brush.face[0].Rotate = 0.; @@ -390,8 +390,8 @@ void MapBrushes(){ XYZtoV( &v[1],&brush.face[1].v[0] ); XYZtoV( &v[4],&brush.face[1].v[1] ); XYZtoV( &v[5],&brush.face[1].v[2] ); - strcpy( brush.face[1].texture, - ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); + Q_strncpyz( brush.face[1].texture, + ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( brush.face[1].texture ) ); brush.face[1].Shift[0] = (float)TexOffset[0]; brush.face[1].Shift[1] = (float)TexOffset[1]; brush.face[1].Rotate = 0.; @@ -404,8 +404,8 @@ void MapBrushes(){ XYZtoV( &v[2],&brush.face[2].v[0] ); XYZtoV( &v[5],&brush.face[2].v[1] ); XYZtoV( &v[3],&brush.face[2].v[2] ); - strcpy( brush.face[2].texture, - ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); + Q_strncpyz( brush.face[2].texture, + ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( brush.face[2].texture ) ); brush.face[2].Shift[0] = (float)TexOffset[0]; brush.face[2].Shift[1] = (float)TexOffset[1]; brush.face[2].Rotate = 0.; @@ -426,21 +426,21 @@ void MapBrushes(){ } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } XYZtoV( &v[3],&brush.face[3].v[0] ); XYZtoV( &v[5],&brush.face[3].v[1] ); XYZtoV( &v[4],&brush.face[3].v[2] ); - strcpy( brush.face[3].texture, - ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? surft : sidetext ) ); + Q_strncpyz( brush.face[3].texture, + ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? surft : sidetext ), sizeof( brush.face[3].texture ) ); brush.face[3].Shift[0] = (float)TexOffset[0]; brush.face[3].Shift[1] = (float)TexOffset[1]; brush.face[3].Rotate = 0.; @@ -461,21 +461,21 @@ void MapBrushes(){ } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } XYZtoV( &v[0],&brush.face[4].v[0] ); XYZtoV( &v[1],&brush.face[4].v[1] ); XYZtoV( &v[2],&brush.face[4].v[2] ); - strcpy( brush.face[4].texture, - ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? sidetext : surft ) ); + Q_strncpyz( brush.face[4].texture, + ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? sidetext : surft ), sizeof( brush.face[4].texture ) ); brush.face[4].Shift[0] = (float)TexOffset[0]; brush.face[4].Shift[1] = (float)TexOffset[1]; brush.face[4].Rotate = 0.; @@ -544,8 +544,8 @@ void MapBrushes(){ XYZtoV( &v[0],&brush.face[0].v[0] ); XYZtoV( &v[3],&brush.face[0].v[1] ); XYZtoV( &v[4],&brush.face[0].v[2] ); - strcpy( brush.face[0].texture, - ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); + Q_strncpyz( brush.face[0].texture, + ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( brush.face[0].texture ) ); brush.face[0].Shift[0] = (float)TexOffset[0]; brush.face[0].Shift[1] = (float)TexOffset[1]; brush.face[0].Rotate = 0.; @@ -558,8 +558,8 @@ void MapBrushes(){ XYZtoV( &v[1],&brush.face[1].v[0] ); XYZtoV( &v[4],&brush.face[1].v[1] ); XYZtoV( &v[5],&brush.face[1].v[2] ); - strcpy( brush.face[1].texture, - ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); + Q_strncpyz( brush.face[1].texture, + ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( brush.face[1].texture ) ); brush.face[1].Shift[0] = (float)TexOffset[0]; brush.face[1].Shift[1] = (float)TexOffset[1]; brush.face[1].Rotate = 0.; @@ -572,8 +572,8 @@ void MapBrushes(){ XYZtoV( &v[2],&brush.face[2].v[0] ); XYZtoV( &v[5],&brush.face[2].v[1] ); XYZtoV( &v[3],&brush.face[2].v[2] ); - strcpy( brush.face[2].texture, - ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ) ); + Q_strncpyz( brush.face[2].texture, + ( strlen( Texture[Game][1] ) ? Texture[Game][1] : Texture[Game][0] ), sizeof( brush.face[2].texture ) ); brush.face[2].Shift[0] = (float)TexOffset[0]; brush.face[2].Shift[1] = (float)TexOffset[1]; brush.face[2].Rotate = 0.; @@ -594,20 +594,20 @@ void MapBrushes(){ } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } XYZtoV( &v[3],&brush.face[3].v[0] ); XYZtoV( &v[5],&brush.face[3].v[1] ); XYZtoV( &v[4],&brush.face[3].v[2] ); - strcpy( brush.face[3].texture, - ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? surft : sidetext ) ); + Q_strncpyz( brush.face[3].texture, + ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? surft : sidetext ), sizeof( brush.face[3].texture ) ); brush.face[3].Shift[0] = (float)TexOffset[0]; brush.face[3].Shift[1] = (float)TexOffset[1]; brush.face[3].Rotate = 0.; @@ -623,25 +623,25 @@ void MapBrushes(){ CrossProduct( t[0],t[1],SurfNormal ); VectorNormalize( SurfNormal,SurfNormal ); if ( DotProduct( SurfNormal,PlaneNormal ) < Steep ) { - strcpy( surft,surftext2 ); + Q_strncpyz( surft, surftext2, sizeof( surft ) ); surf = surface[2]; } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } } else { - strcpy( surft,surftext ); + Q_strncpyz( surft, surftext, sizeof( surft ) ); surf = surface[0]; } XYZtoV( &v[0],&brush.face[4].v[0] ); XYZtoV( &v[1],&brush.face[4].v[1] ); XYZtoV( &v[2],&brush.face[4].v[2] ); - strcpy( brush.face[4].texture, - ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? sidetext : surft ) ); + Q_strncpyz( brush.face[4].texture, + ( Plane == PLANE_XZ0 || Plane == PLANE_XZ1 ? sidetext : surft ), sizeof( brush.face[4].texture ) ); brush.face[4].Shift[0] = (float)TexOffset[0]; brush.face[4].Shift[1] = (float)TexOffset[1]; brush.face[4].Rotate = 0.; @@ -806,7 +806,7 @@ void MapBrushes(){ XYZtoV( &v[0],&brush.face[0].v[0] ); XYZtoV( &v[1],&brush.face[0].v[1] ); XYZtoV( &v[2],&brush.face[0].v[2] ); - strcpy( brush.face[0].texture,skip ); + Q_strncpyz( brush.face[0].texture, skip, sizeof( brush.face[0].texture ) ); brush.face[0].Shift[0] = 0.; brush.face[0].Shift[1] = 0.; brush.face[0].Rotate = 0.; @@ -819,7 +819,7 @@ void MapBrushes(){ XYZtoV( &v[4],&brush.face[1].v[0] ); XYZtoV( &v[7],&brush.face[1].v[1] ); XYZtoV( &v[6],&brush.face[1].v[2] ); - strcpy( brush.face[1].texture,skip ); + Q_strncpyz( brush.face[1].texture, skip, sizeof( brush.face[1].texture ) ); brush.face[1].Shift[0] = 0.; brush.face[1].Shift[1] = 0.; brush.face[1].Rotate = 0.; @@ -832,7 +832,7 @@ void MapBrushes(){ XYZtoV( &v[0],&brush.face[2].v[0] ); XYZtoV( &v[4],&brush.face[2].v[1] ); XYZtoV( &v[5],&brush.face[2].v[2] ); - strcpy( brush.face[2].texture,hint ); + Q_strncpyz( brush.face[2].texture, hint, sizeof( brush.face[2].texture ) ); brush.face[2].Shift[0] = 0.; brush.face[2].Shift[1] = 0.; brush.face[2].Rotate = 0.; @@ -845,7 +845,7 @@ void MapBrushes(){ XYZtoV( &v[1],&brush.face[3].v[0] ); XYZtoV( &v[5],&brush.face[3].v[1] ); XYZtoV( &v[6],&brush.face[3].v[2] ); - strcpy( brush.face[3].texture,hint ); + Q_strncpyz( brush.face[3].texture, hint, sizeof( brush.face[3].texture ) ); brush.face[3].Shift[0] = 0.; brush.face[3].Shift[1] = 0.; brush.face[3].Rotate = 0.; @@ -858,7 +858,7 @@ void MapBrushes(){ XYZtoV( &v[2],&brush.face[4].v[0] ); XYZtoV( &v[6],&brush.face[4].v[1] ); XYZtoV( &v[7],&brush.face[4].v[2] ); - strcpy( brush.face[4].texture,hint ); + Q_strncpyz( brush.face[4].texture, hint, sizeof( brush.face[4].texture ) ); brush.face[4].Shift[0] = 0.; brush.face[4].Shift[1] = 0.; brush.face[4].Rotate = 0.; @@ -871,7 +871,7 @@ void MapBrushes(){ XYZtoV( &v[3],&brush.face[5].v[0] ); XYZtoV( &v[7],&brush.face[5].v[1] ); XYZtoV( &v[4],&brush.face[5].v[2] ); - strcpy( brush.face[5].texture,hint ); + Q_strncpyz( brush.face[5].texture, hint, sizeof( brush.face[5].texture ) ); brush.face[5].Shift[0] = 0.; brush.face[5].Shift[1] = 0.; brush.face[5].Rotate = 0.; @@ -892,7 +892,7 @@ void MapBrushes(){ brush.NumFaces = 5; for ( i = 0; i < 6; i++ ) { - strcpy( brush.face[i].texture,hint ); + Q_strncpyz( brush.face[i].texture, hint, sizeof( brush.face[i].texture ) ); brush.face[i].Shift[0] = 0.; brush.face[i].Shift[1] = 0.; brush.face[i].Rotate = 0.; @@ -2015,7 +2015,7 @@ void MakePatch( patchMesh_t *p ){ ret = g_FuncTable.m_pfnCreatePatchHandle(); // strcpy(shadername, "textures/"); // strcpy(shadername+9, Texture[Game][0]); - strcpy( shadername, Texture[Game][0] ); + Q_strncpyz( shadername, Texture[Game][0], sizeof( shadername ) ); g_FuncTable.m_pfnCommitPatchHandleToMap( ret,p,shadername ); g_FuncTable.m_pfnReleasePatchHandles(); } @@ -2037,12 +2037,12 @@ void MakeBrush( BRUSH *brush ){ for ( i = 0; i < brush->NumFaces; i++ ) { if ( !strncmp( brush->face[i].texture, "textures/", 9 ) ) { - strcpy( QERFaceData.m_TextureName,brush->face[i].texture ); + Q_strncpyz( QERFaceData.m_TextureName, brush->face[i].texture, sizeof( QERFaceData.m_TextureName ) ); } else { - strcpy( QERFaceData.m_TextureName,"textures/" ); - strcpy( QERFaceData.m_TextureName + 9,brush->face[i].texture ); + strcpy( QERFaceData.m_TextureName, "textures/" ); + Q_strncpyz( QERFaceData.m_TextureName + 9,brush->face[i].texture, sizeof( QERFaceData.m_TextureName ) - 9 ); } QERFaceData.m_nContents = brush->face[i].Contents; QERFaceData.m_nFlags = brush->face[i].Surface; diff --git a/contrib/gtkgensurf/gensurf.cpp b/contrib/gtkgensurf/gensurf.cpp index fc0eedb8..f210a1ef 100644 --- a/contrib/gtkgensurf/gensurf.cpp +++ b/contrib/gtkgensurf/gensurf.cpp @@ -100,15 +100,15 @@ char GameName[NUMGAMES][16] = {"Quake2", "Half-Life", "SiN", "Heretic2", "Kingpi bool GenSurfInit(){ - strcpy( gszVersion, "1.05" ); - strcpy( gszCaption, "GtkGenSurf" ); + Q_strncpyz( gszVersion, "1.05", sizeof( gszVersion ) ); + Q_strncpyz( gszCaption, "GtkGenSurf", sizeof( gszCaption ) ); if ( strlen( gszVersion ) ) { - strcat( gszCaption, " v" ); - strcat( gszCaption, gszVersion ); + strncat( gszCaption, " v", sizeof( gszCaption ) ); + strncat( gszCaption, gszVersion, sizeof( gszCaption ) ); } - strcpy( gszIni, g_FuncTable.m_pfnProfileGetDirectory() ); - strcat( gszIni, "gensurf.ini" ); + Q_strncpyz( gszIni, g_FuncTable.m_pfnProfileGetDirectory(), sizeof( gszIni ) ); + strncat( gszIni, "gensurf.ini", sizeof( gszIni ) ); /*if (g_FuncTable.m_pfnReadProjectKey != NULL) { @@ -273,9 +273,9 @@ void ReadIniFile( const char *file ){ for ( i = 0; i < NUMGAMES; i++ ) { // strcpy (gszOutputDir[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"OutputDir","")); - strcpy( Texture[i][0], g_FuncTable.m_pfnProfileLoadString( file, GameName[i], "Texture", "" ) ); - strcpy( Texture[i][1], g_FuncTable.m_pfnProfileLoadString( file, GameName[i], "Texture2", "" ) ); - strcpy( Texture[i][2], g_FuncTable.m_pfnProfileLoadString( file, GameName[i], "Texture3", "" ) ); + Q_strncpyz( Texture[i][0], g_FuncTable.m_pfnProfileLoadString( file, GameName[i], "Texture", "" ), sizeof( Texture[i][0] ) ); + Q_strncpyz( Texture[i][1], g_FuncTable.m_pfnProfileLoadString( file, GameName[i], "Texture2", "" ), sizeof( Texture[i][1] ) ); + Q_strncpyz( Texture[i][2], g_FuncTable.m_pfnProfileLoadString( file, GameName[i], "Texture3", "" ), sizeof( Texture[i][2] ) ); // strcpy (gszTextureDir[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"TextureDir","")); // UsePak[i] = GetPrivateProfileInt(GameName[i],"UsePak",0); // strcpy (pakfile[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"PakFile","")); @@ -312,7 +312,7 @@ void ReadIniFile( const char *file ){ if ( !strlen( Texture[QUAKE3][1] ) ) { strcpy( Texture[QUAKE3][1], "textures/common/caulk" ); } - strcpy( gbmp.name, g_FuncTable.m_pfnProfileLoadString( file, "Bitmap","Filename","" ) ); + Q_strncpyz( gbmp.name, g_FuncTable.m_pfnProfileLoadString( file, "Bitmap","Filename","" ), sizeof( gbmp.name ) ); gbmp.colors = NULL; @@ -320,7 +320,7 @@ void ReadIniFile( const char *file ){ OpenBitmap(); } - strcpy( gbmp.defpath, g_FuncTable.m_pfnProfileLoadString( file, "Bitmap","DefaultPath","" ) ); + Q_strncpyz( gbmp.defpath, g_FuncTable.m_pfnProfileLoadString( file, "Bitmap","DefaultPath","" ), sizeof( gbmp.defpath ) ); Text = g_FuncTable.m_pfnProfileLoadString( file, "Bitmap","BlackValue","" ); if ( strlen( Text ) ) { @@ -428,16 +428,16 @@ void SaveSetup( GtkWidget *parent ){ WriteIniFile( name ); g_FuncTable.m_pfnProfileSaveString( name, OPTS_SECTION,"MapFile",gszMapFile ); - sprintf( text,"0x%04x",FileAppend ); + snprintf( text, sizeof( text ), "0x%04x", FileAppend ); g_FuncTable.m_pfnProfileSaveString( name, OPTS_SECTION,"Append",text ); - sprintf( text,"0x%04x",Decimate ); + snprintf( text, sizeof( text ), "0x%04x", Decimate ); g_FuncTable.m_pfnProfileSaveString( name, OPTS_SECTION,"Decimate",text ); for ( i = 0; i <= NH; i++ ) { for ( j = 0; j <= NV; j++ ) { if ( xyz[i][j].fixed ) { - sprintf( key, "I%dJ%d", i, j ); + snprintf( key, sizeof( key ), "I%dJ%d", i, j ); snprintf( text, sizeof( text ), "%g %g %g", xyz[i][j].fixed_value, xyz[i][j].range, xyz[i][j].rate ); g_FuncTable.m_pfnProfileSaveString( name, "FixedPoints",key,text ); } @@ -469,7 +469,7 @@ void OpenSetup( GtkWidget *parent, int UseDefaults ){ { for ( j = 0; j <= NV; j++ ) { - sprintf( key,"I%dJ%d",i,j ); + snprintf( key, sizeof( key ), "I%dJ%d", i, j ); text = g_FuncTable.m_pfnProfileLoadString( name, "FixedPoints", key, "" ); if ( strlen( text ) ) { xyz[i][j].fixed = 1; diff --git a/contrib/gtkgensurf/triangle.c b/contrib/gtkgensurf/triangle.c index 5bf1a1db..8ec7045d 100644 --- a/contrib/gtkgensurf/triangle.c +++ b/contrib/gtkgensurf/triangle.c @@ -313,6 +313,11 @@ #include "triangle.h" #endif /* TRILIBRARY */ +#ifndef Q_strncpyz +#define Q_strncpyz(_dst, _source, _len) do { strncpy((_dst), (_source), (_len) - 1); (_dst)[(_len) - 1] = 0; } while( 0 ) +#endif + + /* The following obscenity seems to be necessary to ensure that this program */ /* will port to Dec Alphas running OSF/1, because their stdio.h file commits */ /* the unpardonable sin of including stdlib.h. Hence, malloc(), free(), and */ @@ -2857,8 +2862,7 @@ char **argv; } #ifndef TRILIBRARY } else { - strncpy( innodefilename, argv[i], FILENAMESIZE - 1 ); - innodefilename[FILENAMESIZE - 1] = '\0'; + Q_strncpyz( innodefilename, argv[i], FILENAMESIZE ); } #endif /* not TRILIBRARY */ } @@ -2907,11 +2911,11 @@ char **argv; } #ifndef TRILIBRARY - strcpy( inpolyfilename, innodefilename ); - strcpy( inelefilename, innodefilename ); - strcpy( areafilename, innodefilename ); + Q_strncpyz( inpolyfilename, innodefilename, sizeof( inpolyfilename ) ); + Q_strncpyz( inelefilename, innodefilename, sizeof( inelefilename ) ); + Q_strncpyz( areafilename, innodefilename, sizeof( areafilename ) ); increment = 0; - strcpy( workstring, innodefilename ); + Q_strncpyz( workstring, innodefilename, sizeof( workstring ) ); j = 1; while ( workstring[j] != '\0' ) { if ( ( workstring[j] == '.' ) && ( workstring[j + 1] != '\0' ) ) { @@ -2933,64 +2937,64 @@ char **argv; } while ( workstring[j] != '\0' ); } if ( noiterationnum ) { - strcpy( outnodefilename, innodefilename ); - strcpy( outelefilename, innodefilename ); - strcpy( edgefilename, innodefilename ); - strcpy( vnodefilename, innodefilename ); - strcpy( vedgefilename, innodefilename ); - strcpy( neighborfilename, innodefilename ); - strcpy( offfilename, innodefilename ); - strcat( outnodefilename, ".node" ); - strcat( outelefilename, ".ele" ); - strcat( edgefilename, ".edge" ); - strcat( vnodefilename, ".v.node" ); - strcat( vedgefilename, ".v.edge" ); - strcat( neighborfilename, ".neigh" ); - strcat( offfilename, ".off" ); + Q_strncpyz( outnodefilename, innodefilename, sizeof( outnodefilename ) ); + Q_strncpyz( outelefilename, innodefilename, sizeof( outelefilename ) ); + Q_strncpyz( edgefilename, innodefilename, sizeof( edgefilename ) ); + Q_strncpyz( vnodefilename, innodefilename, sizeof( vnodefilename ) ); + Q_strncpyz( vedgefilename, innodefilename, sizeof( vedgefilename ) ); + Q_strncpyz( neighborfilename, innodefilename, sizeof( neighborfilename ) ); + Q_strncpyz( offfilename, innodefilename, sizeof( offfilename ) ); + strncat( outnodefilename, ".node", sizeof( outnodefilename ) ); + strncat( outelefilename, ".ele", sizeof( outelefilename ) ); + strncat( edgefilename, ".edge", sizeof( edgefilename ) ); + strncat( vnodefilename, ".v.node", sizeof( vnodefilename ) ); + strncat( vedgefilename, ".v.edge", sizeof( vedgefilename ) ); + strncat( neighborfilename, ".neigh", sizeof( neighborfilename ) ); + strncat( offfilename, ".off", sizeof( offfilename ) ); } else if ( increment == 0 ) { - strcpy( outnodefilename, innodefilename ); - strcpy( outpolyfilename, innodefilename ); - strcpy( outelefilename, innodefilename ); - strcpy( edgefilename, innodefilename ); - strcpy( vnodefilename, innodefilename ); - strcpy( vedgefilename, innodefilename ); - strcpy( neighborfilename, innodefilename ); - strcpy( offfilename, innodefilename ); - strcat( outnodefilename, ".1.node" ); - strcat( outpolyfilename, ".1.poly" ); - strcat( outelefilename, ".1.ele" ); - strcat( edgefilename, ".1.edge" ); - strcat( vnodefilename, ".1.v.node" ); - strcat( vedgefilename, ".1.v.edge" ); - strcat( neighborfilename, ".1.neigh" ); - strcat( offfilename, ".1.off" ); + Q_strncpyz( outnodefilename, innodefilename, sizeof( outnodefilename ) ); + Q_strncpyz( outpolyfilename, innodefilename, sizeof( outpolyfilename ) ); + Q_strncpyz( outelefilename, innodefilename, sizeof( outelefilename ) ); + Q_strncpyz( edgefilename, innodefilename, sizeof( edgefilename ) ); + Q_strncpyz( vnodefilename, innodefilename, sizeof( vnodefilename ) ); + Q_strncpyz( vedgefilename, innodefilename, sizeof( vedgefilename ) ); + Q_strncpyz( neighborfilename, innodefilename, sizeof( neighborfilename ) ); + Q_strncpyz( offfilename, innodefilename, sizeof( offfilename ) ); + strncat( outnodefilename, ".1.node", sizeof( outnodefilename ) ); + strncat( outpolyfilename, ".1.poly", sizeof( outpolyfilename ) ); + strncat( outelefilename, ".1.ele", sizeof( outelefilename ) ); + strncat( edgefilename, ".1.edge", sizeof( edgefilename ) ); + strncat( vnodefilename, ".1.v.node", sizeof( vnodefilename ) ); + strncat( vedgefilename, ".1.v.edge", sizeof( vedgefilename ) ); + strncat( neighborfilename, ".1.neigh", sizeof( neighborfilename ) ); + strncat( offfilename, ".1.off", sizeof( offfilename ) ); } else { workstring[increment] = '%'; workstring[increment + 1] = 'd'; workstring[increment + 2] = '\0'; - sprintf( outnodefilename, workstring, meshnumber + 1 ); - strcpy( outpolyfilename, outnodefilename ); - strcpy( outelefilename, outnodefilename ); - strcpy( edgefilename, outnodefilename ); - strcpy( vnodefilename, outnodefilename ); - strcpy( vedgefilename, outnodefilename ); - strcpy( neighborfilename, outnodefilename ); - strcpy( offfilename, outnodefilename ); - strcat( outnodefilename, ".node" ); - strcat( outpolyfilename, ".poly" ); - strcat( outelefilename, ".ele" ); - strcat( edgefilename, ".edge" ); - strcat( vnodefilename, ".v.node" ); - strcat( vedgefilename, ".v.edge" ); - strcat( neighborfilename, ".neigh" ); - strcat( offfilename, ".off" ); + snprintf( outnodefilename, sizeof( outnodefilename ), workstring, meshnumber + 1 ); + Q_strncpyz( outpolyfilename, outnodefilename, sizeof( outpolyfilename ) ); + Q_strncpyz( outelefilename, outnodefilename, sizeof( outelefilename ) ); + Q_strncpyz( edgefilename, outnodefilename, sizeof( edgefilename ) ); + Q_strncpyz( vnodefilename, outnodefilename, sizeof( vnodefilename ) ); + Q_strncpyz( vedgefilename, outnodefilename, sizeof( vedgefilename ) ); + Q_strncpyz( neighborfilename, outnodefilename, sizeof( neighborfilename ) ); + Q_strncpyz( offfilename, outnodefilename, sizeof( offfilename ) ); + strncat( outnodefilename, ".node", sizeof( outnodefilename ) ); + strncat( outpolyfilename, ".poly", sizeof( outpolyfilename ) ); + strncat( outelefilename, ".ele", sizeof( outelefilename ) ); + strncat( edgefilename, ".edge", sizeof( edgefilename ) ); + strncat( vnodefilename, ".v.node", sizeof( vnodefilename ) ); + strncat( vedgefilename, ".v.edge", sizeof( vedgefilename ) ); + strncat( neighborfilename, ".neigh", sizeof( neighborfilename ) ); + strncat( offfilename, ".off", sizeof( offfilename ) ); } - strcat( innodefilename, ".node" ); - strcat( inpolyfilename, ".poly" ); - strcat( inelefilename, ".ele" ); - strcat( areafilename, ".area" ); + strncat( innodefilename, ".node", sizeof( innodefilename ) ); + strncat( inpolyfilename, ".poly", sizeof( inpolyfilename ) ); + strncat( inelefilename, ".ele", sizeof( inelefilename ) ); + strncat( areafilename, ".area", sizeof( areafilename ) ); #endif /* not TRILIBRARY */ } @@ -10046,7 +10050,7 @@ char *polyfilename; printf( "Inserting segments into Delaunay triangulation.\n" ); } #ifdef TRILIBRARY - strcpy( polyfilename, "input" ); + Q_strncpyz( polyfilename, "input", sizeof( polyfilename ) ); segments = numberofsegments; segmentmarkers = segmentmarkerlist != (int *) NULL; index = 0; diff --git a/contrib/gtkgensurf/view.cpp b/contrib/gtkgensurf/view.cpp index 7c02fc23..9542af2a 100644 --- a/contrib/gtkgensurf/view.cpp +++ b/contrib/gtkgensurf/view.cpp @@ -322,14 +322,14 @@ static void motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ){ { case PLANE_XZ0: case PLANE_XZ1: - sprintf( Text," x=%d, z=%d ",(int)( floor( x - 0.5 ) + 1. ),(int)( floor( y - 0.5 ) + 1. ) ); + snprintf( Text, sizeof( Text ), " x=%d, z=%d ", (int)( floor( x - 0.5 ) + 1. ), (int)( floor( y - 0.5 ) + 1. ) ); break; case PLANE_YZ0: case PLANE_YZ1: - sprintf( Text," y=%d, z=%d ",(int)( floor( x - 0.5 ) + 1. ),(int)( floor( y - 0.5 ) + 1. ) ); + snprintf( Text, sizeof( Text ), " y=%d, z=%d ", (int)( floor( x - 0.5 ) + 1. ), (int)( floor( y - 0.5 ) + 1. ) ); break; default: - sprintf( Text," x=%d, y=%d ",(int)( floor( x - 0.5 ) + 1. ),(int)( floor( y - 0.5 ) + 1. ) ); + snprintf( Text, sizeof( Text ), " x=%d, y=%d ", (int)( floor( x - 0.5 ) + 1. ), (int)( floor( y - 0.5 ) + 1. ) ); } texfont_write( Text, rcCoord.left, rcCoord.top ); diff --git a/contrib/prtview/ConfigDialog.cpp b/contrib/prtview/ConfigDialog.cpp index 5a67cbeb..7aa61510 100644 --- a/contrib/prtview/ConfigDialog.cpp +++ b/contrib/prtview/ConfigDialog.cpp @@ -86,17 +86,17 @@ static int DoColor( GdkRGBA *color ){ } static void Set2DText( GtkWidget* label ){ - char s[40]; + char s[64]; - sprintf( s, "Line Width = %6.3f", portals.width_2d * 0.5f ); + snprintf( s, sizeof( s ), "Line Width = %6.3f", portals.width_2d * 0.5f ); gtk_label_set_text( GTK_LABEL( label ), s ); } static void Set3DText( GtkWidget* label ){ - char s[40]; + char s[64]; - sprintf( s, "Line Width = %6.3f", portals.width_3d * 0.5f ); + snprintf( s, sizeof( s ), "Line Width = %6.3f", portals.width_3d * 0.5f ); gtk_label_set_text( GTK_LABEL( label ), s ); } @@ -104,7 +104,7 @@ static void Set3DText( GtkWidget* label ){ static void Set3DTransText( GtkWidget* label ){ char s[40]; - sprintf( s, "Polygon transparency = %d%%", (int)portals.trans_3d ); + snprintf( s, sizeof( s ), "Polygon transparency = %d%%", (int)portals.trans_3d ); gtk_label_set_text( GTK_LABEL( label ), s ); } @@ -112,7 +112,7 @@ static void Set3DTransText( GtkWidget* label ){ static void SetClipText( GtkWidget* label ){ char s[40]; - sprintf( s, "Cubic clip range = %d", (int)portals.clip_range * 64 ); + snprintf( s, sizeof( s ), "Cubic clip range = %d", (int)portals.clip_range * 64 ); gtk_label_set_text( GTK_LABEL( label ), s ); } diff --git a/libs/cmdlib.h b/libs/cmdlib.h index 2417760b..15f06eb6 100644 --- a/libs/cmdlib.h +++ b/libs/cmdlib.h @@ -65,10 +65,10 @@ void DefaultExtension( char *path, char *extension, size_t length ); void DefaultPath( char *path, const char *basepath, size_t length ); void StripFilename( char *path ); void StripExtension( char *path ); -void ExtractFilePath( const char *path, char *dest ); -void ExtractFileName( const char *path, char *dest ); -void ExtractFileBase( const char *path, char *dest ); -void ExtractFileExtension( const char *path, char *dest, size_t length ); +void ExtractFilePath( const char *path, char *dest, size_t size ); +void ExtractFileName( const char *path, char *dest, size_t size ); +void ExtractFileBase( const char *path, char *dest, size_t size ); +void ExtractFileExtension( const char *path, char *dest, size_t size ); /*! \brief create all directories leading to a file path. if you pass a directory, terminate it with a '/' */ diff --git a/libs/cmdlib/cmdlib.cpp b/libs/cmdlib/cmdlib.cpp index c1f81e7a..3c7857b0 100644 --- a/libs/cmdlib/cmdlib.cpp +++ b/libs/cmdlib/cmdlib.cpp @@ -221,8 +221,9 @@ void StripExtension( char *path ){ Extract file parts ==================== */ -void ExtractFilePath( const char *path, char *dest ){ +void ExtractFilePath( const char *path, char *dest, size_t size ){ const char *src; + size_t length; src = path + strlen( path ) - 1; @@ -232,13 +233,20 @@ void ExtractFilePath( const char *path, char *dest ){ while ( src != path && *( src - 1 ) != '/' && *( src - 1 ) != '\\' ) src--; - memcpy( dest, path, src - path ); - dest[src - path] = 0; + length = src - path; + if( length + 1 > size ) + { + length = size - 1; + } + memcpy( dest, path, length ); + dest[length] = 0; } -void ExtractFileName( const char *path, char *dest ){ +void ExtractFileName( const char *path, char *dest, size_t size ){ const char *src; + if( size <= 0 ) + return; src = path + strlen( path ) - 1; // @@ -250,7 +258,13 @@ void ExtractFileName( const char *path, char *dest ){ while ( *src ) { + if( size == 1 ) + { + *dest = 0; + return; + } *dest++ = *src++; + size--; } *dest = 0; } @@ -278,14 +292,18 @@ inline unsigned int filename_get_base_length( const char* filename ){ return ( last_period != NULL ) ? last_period - filename : strlen( filename ); } -void ExtractFileBase( const char *path, char *dest ){ +void ExtractFileBase( const char *path, char *dest, size_t size ){ const char* filename = path_get_filename_start( path ); unsigned int length = filename_get_base_length( filename ); + if( length > size ) + { + length = size; - 1; + } strncpy( dest, filename, length ); dest[length] = '\0'; } -void ExtractFileExtension( const char *path, char *dest, size_t length ){ +void ExtractFileExtension( const char *path, char *dest, size_t size ){ const char *src; src = path + strlen( path ) - 1; @@ -300,7 +318,7 @@ void ExtractFileExtension( const char *path, char *dest, size_t length ){ return; } - Q_strncpyz( dest, src, length ); + Q_strncpyz( dest, src, size ); } @@ -338,7 +356,7 @@ void CreateDirectoryPath( const char *path ) { char *src; char back; - ExtractFilePath( path, base ); + ExtractFilePath( path, base, sizeof( base ) ); src = base + 1; while ( 1 ) { diff --git a/libs/picomodel/lwo/pntspols.c b/libs/picomodel/lwo/pntspols.c index 66a30bd7..965ebda8 100644 --- a/libs/picomodel/lwo/pntspols.c +++ b/libs/picomodel/lwo/pntspols.c @@ -395,8 +395,7 @@ int lwResolvePolySurfaces( lwPolygonList *polygon, lwTagList *tlist, if ( !s[ index ]->name ) { return 0; } - strncpy( s[ index ]->name, tlist->tag[ index ], sizeof( s[ index ]->name ) - 1 ); - s[ index ]->name[sizeof( s[ index ]->name ) - 1] = 0; + strcpy( s[ index ]->name, tlist->tag[ index ] ); lwListAdd( (void **) surf, s[ index ] ); *nsurfs = *nsurfs + 1; } diff --git a/libs/picomodel/picointernal.h b/libs/picomodel/picointernal.h index c4d935ae..39f3f159 100644 --- a/libs/picomodel/picointernal.h +++ b/libs/picomodel/picointernal.h @@ -54,6 +54,12 @@ extern "C" #include "picomodel.h" +#if defined(_MSC_VER) && _MSC_VER<1900 && !(defined snprintf) +#define snprintf _snprintf +#endif +#ifndef Q_strncpyz +#define Q_strncpyz(_dst, _source, _len) do { strncpy((_dst), (_source), (_len) - 1); (_dst)[(_len) - 1] = 0; } while( 0 ) +#endif /* os dependant replacements */ #if WIN32 || _WIN32 diff --git a/libs/picomodel/picomodel.c b/libs/picomodel/picomodel.c index 1e1bcfae..946ec96d 100644 --- a/libs/picomodel/picomodel.c +++ b/libs/picomodel/picomodel.c @@ -216,8 +216,7 @@ picoModel_t *PicoLoadModel( char *fileName, int frameNum ){ remapFileName = _pico_alloc( length ); if ( remapFileName != NULL ) { /* copy model file name and change extension */ - strncpy( remapFileName, modelFileName, length ); - remapFileName[length - 1] = 0; + Q_strncpyz( remapFileName, modelFileName, length ); _pico_setfext( remapFileName, "remap", length ); /* try to remap model; we don't handle the result */ @@ -511,7 +510,7 @@ picoSurface_t *PicoNewSurface( picoModel_t *model ){ surface->model = model; /* set default name */ - sprintf( surfaceName, "Unnamed_%d", model->numSurfaces ); + snprintf( surfaceName, sizeof( surfaceName ), "Unnamed_%d", model->numSurfaces ); PicoSetSurfaceName( surface, surfaceName ); } diff --git a/libs/picomodel/pm_3ds.c b/libs/picomodel/pm_3ds.c index d7a0ea39..f00bcddd 100644 --- a/libs/picomodel/pm_3ds.c +++ b/libs/picomodel/pm_3ds.c @@ -421,26 +421,23 @@ static int GetMeshShader( T3dsLoaderPers *pers ){ char *name; /* copy map name to local buffer */ - strncpy( mapName, mapNamePtr, sizeof( mapName ) - 1 ); - mapName[sizeof( mapName ) - 1] = 0; + Q_strncpyz( mapName, mapNamePtr, sizeof( mapName ) ); /* extract file name */ name = _pico_nopath( mapName ); - strncpy( temp, name, sizeof( temp ) - 1 ); - temp[sizeof( temp ) - 1] = 0; + Q_strncpyz( temp, name, sizeof( temp ) ); /* remove file extension */ /* name = _pico_setfext( name,"" ); */ /* assign default name if no name available */ if ( strlen( temp ) < 1 ) { - strncpy( temp, pers->basename, sizeof( temp ) - 1 ); - temp[sizeof( temp ) - 1] = 0; + Q_strncpyz( temp, pers->basename, sizeof( temp ) ); } /* build shader name */ _pico_strlwr( temp ); /* gaynux update -sea */ - sprintf( mapName,"models/mapobjects/%s/%s",pers->basename,temp ); + snprintf( mapName, sizeof( mapName ), "models/mapobjects/%s/%s", pers->basename, temp ); /* set shader name */ /* PicoSetShaderName( shader,mapName ); */ /* ydnar: this will screw up the named shader */ @@ -733,8 +730,7 @@ static picoModel_t *_3ds_load( PM_PARAMS_LOAD ){ return NULL; } /* get model's base name (eg. jeep from c:\models\jeep.3ds) */ - strncpy( basename, _pico_nopath( fileName ), sizeof( basename ) - 1 ); - basename[sizeof( basename ) - 1] = 0; + Q_strncpyz( basename, _pico_nopath( fileName ), sizeof( basename ) ); _pico_setfext( basename, "", sizeof( basename ) ); /* initialize persistant vars (formerly static) */ diff --git a/libs/picomodel/pm_ase.c b/libs/picomodel/pm_ase.c index 80e0eddd..491d0cb8 100644 --- a/libs/picomodel/pm_ase.c +++ b/libs/picomodel/pm_ase.c @@ -408,8 +408,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ } /* remember node name */ - strncpy( lastNodeName, ptr, sizeof( lastNodeName ) - 1 ); - lastNodeName[sizeof( lastNodeName ) - 1] = 0; + Q_strncpyz( lastNodeName, ptr, sizeof( lastNodeName ) ); } /* model mesh (originally contained within geomobject) */ else if ( !_pico_stricmp( p->token, "*mesh" ) ) { @@ -802,7 +801,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ _ase_error_return( "Missing material name" ); } - strncpy( materialName, name, sizeof( materialName ) - 1 ); + Q_strncpyz( materialName, name, sizeof( materialName ) ); materialName[sizeof( materialName ) - 1] = 0; /* skip rest and continue with next token */ _pico_parse_skip_rest( p ); diff --git a/libs/picomodel/pm_fm.c b/libs/picomodel/pm_fm.c index e4fcea1c..9b2181fa 100644 --- a/libs/picomodel/pm_fm.c +++ b/libs/picomodel/pm_fm.c @@ -350,8 +350,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ){ texCoord->t = _pico_little_short( texCoord[i].t ); } // set Skin Name - strncpy( skinname, (char *) fm.fm_skin, FM_SKINPATHSIZE - 1 ); - skinname[FM_SKINPATHSIZE - 1] = 0; + Q_strncpyz( skinname, (char *) fm.fm_skin, FM_SKINPATHSIZE ); #ifdef FM_VERBOSE_DBG // Print out md2 values diff --git a/libs/picomodel/pm_lwo.c b/libs/picomodel/pm_lwo.c index 399df6a0..2930cfe0 100644 --- a/libs/picomodel/pm_lwo.c +++ b/libs/picomodel/pm_lwo.c @@ -234,8 +234,7 @@ static picoModel_t *_lwo_load( PM_PARAMS_LOAD ){ } /* detox and set shader name */ - strncpy( name, surface->name, sizeof( name ) - 1 ); - name[sizeof( name ) - 1] = 0; + Q_strncpyz( name, surface->name, sizeof( name ) ); _pico_setfext( name, "", sizeof( name ) ); _pico_unixify( name ); PicoSetShaderName( picoShader, name ); diff --git a/libs/picomodel/pm_md2.c b/libs/picomodel/pm_md2.c index 96831583..15cf7316 100644 --- a/libs/picomodel/pm_md2.c +++ b/libs/picomodel/pm_md2.c @@ -431,8 +431,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ){ } // set Skin Name - strncpy( skinname, (char *) ( bb + md2->ofsSkins ), MD2_MAX_SKINNAME - 1 ); - skinname[MD2_MAX_SKINNAME - 1] = 0; + Q_strncpyz( skinname, (char *) ( bb + md2->ofsSkins ), MD2_MAX_SKINNAME ); // Print out md2 values _pico_printf( PICO_VERBOSE,"Skins: %d Verts: %d STs: %d Triangles: %d Frames: %d\nSkin Name \"%s\"\n", md2->numSkins, md2->numXYZ, md2->numST, md2->numTris, md2->numFrames, skinname ); @@ -440,8 +439,8 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ){ // relative texture path - allows moving of models in game dir structure without changing the skinpath // e.g. used in ufo:ai if ( skinname[0] == '.' ) { - strncpy( path, fileName, MD2_MAX_SKINNAME - 1 ); - path[MD2_MAX_SKINNAME - 1] = 0; + Q_strncpyz( path, fileName, MD2_MAX_SKINNAME ); + for ( i = MD2_MAX_SKINNAME; i--; ) { // skip filename if ( path[i] == '/' || path[i] == '\\' ) { @@ -450,8 +449,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ){ path[i] = '\0'; } strncat( path, &skinname[1], MD2_MAX_SKINNAME ); - strncpy( skinname, path, MD2_MAX_SKINNAME - 1 ); - skinname[MD2_MAX_SKINNAME - 1] = 0; + Q_strncpyz( skinname, path, MD2_MAX_SKINNAME ); // Print out md2 values _pico_printf( PICO_VERBOSE,"Relative skin path converted to: \"%s\" (%s)\n", skinname, fileName ); diff --git a/libs/splines/math_vector.cpp b/libs/splines/math_vector.cpp index 009c116e..a72bc07a 100644 --- a/libs/splines/math_vector.cpp +++ b/libs/splines/math_vector.cpp @@ -136,7 +136,7 @@ idVec3 LerpVector( idVec3 &w1, idVec3 &w2, const float t ) { */ char *idVec3::string( void ) { static int index = 0; - static char str[ 8 ][ 36 ]; + static char str[ 8 ][ 256 ]; char *s; // use an array so that multiple toString's won't collide diff --git a/libs/splines/splines.cpp b/libs/splines/splines.cpp index fe86f4db..c08cb5ea 100644 --- a/libs/splines/splines.cpp +++ b/libs/splines/splines.cpp @@ -553,8 +553,7 @@ bool idCameraDef::getCameraInfo( long time, idVec3 &origin, idVec3 &direction, f //} } else if ( events[i]->getType() == idCameraEvent::EVENT_FOV ) { - strncpy( buff, events[i]->getParam(), sizeof( buff ) - 1 ); - buff[sizeof( buff ) - 1] = 0; + Q_strncpyz( buff, events[i]->getParam(), sizeof( buff ) ); const char *param1 = strtok( buff, " \t,\0" ); const char *param2 = strtok( NULL, " \t,\0" ); float len = ( param2 ) ? atof( param2 ) : 0; @@ -574,8 +573,7 @@ bool idCameraDef::getCameraInfo( long time, idVec3 &origin, idVec3 &direction, f } else if ( events[i]->getType() == idCameraEvent::EVENT_CAMERA ) { memset( buff, 0, sizeof( buff ) ); - strncpy( buff, events[i]->getParam(), sizeof( buff ) - 1 ); - buff[sizeof( buff ) - 1] = 0; + Q_strncpyz( buff, events[i]->getParam(), sizeof( buff ) ); const char *param1 = strtok( buff, " \t,\0" ); const char *param2 = strtok( NULL, " \t,\0" ); diff --git a/plugins/eclassfgd/plugin.cpp b/plugins/eclassfgd/plugin.cpp index 35a50077..3b2a8edc 100644 --- a/plugins/eclassfgd/plugin.cpp +++ b/plugins/eclassfgd/plugin.cpp @@ -450,7 +450,7 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ // COLOR if ( bc->gotcolor ) { memcpy( e->color, bc->color, sizeof( vec3_t ) ); - sprintf( color, "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); + snprintf( color, sizeof( color ), "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); e->texdef.SetName( color ); } @@ -547,7 +547,7 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ e->color[1] = 0.5; // how about a nice bright pink, mmm, nice! :) e->color[2] = 1; - sprintf( color, "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); + snprintf( color, sizeof( color ), "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); e->texdef.SetName( color ); } } @@ -1069,21 +1069,21 @@ void Eclass_ScanFile( char *filename ){ Sys_Printf( "%s", (char *)tmp->data ); } if ( tmpclass->gotsize ) { - sprintf( temp,"(%.0f %.0f %.0f) - (%.0f %.0f %.0f)",tmpclass->boundingbox[0][0], + snprintf( temp, sizeof( temp ),"(%.0f %.0f %.0f) - (%.0f %.0f %.0f)",tmpclass->boundingbox[0][0], tmpclass->boundingbox[0][1], tmpclass->boundingbox[0][2], tmpclass->boundingbox[1][0], tmpclass->boundingbox[1][1], tmpclass->boundingbox[1][2] ); } - else{ strcpy( temp,"No Size" ); } + else{ Q_strncpyz( temp, "No Size", sizeof( temp ) ); } Sys_Printf( ") '%s' Size: %s",tmpclass->description ? tmpclass->description : "No description",temp ); if ( tmpclass->gotcolor ) { - sprintf( temp,"(%d %d %d)",tmpclass->color[0], + snprintf( temp, sizeof( temp ), "(%d %d %d)", tmpclass->color[0], tmpclass->color[1], tmpclass->color[2] ); } - else{ strcpy( temp,"No Color" ); } + else{ Q_strncpyz( temp, "No Color", sizeof( temp ) ); } Sys_Printf( " Color: %s Options:\n",temp ); if ( !tmpclass->l_optionlist ) { Sys_Printf( " No Options\n" ); diff --git a/plugins/map/parse.cpp b/plugins/map/parse.cpp index 01ee011c..25f79780 100644 --- a/plugins/map/parse.cpp +++ b/plugins/map/parse.cpp @@ -30,7 +30,7 @@ #include "plugin.h" // cmdlib -extern void ExtractFileName( const char *path, char *dest ); +extern void ExtractFileName( const char *path, char *dest, size_t size ); extern int g_MapVersion; int abortcode; // see imap.h for values. @@ -65,7 +65,7 @@ void BuildWadList( char *wadstr ){ g_WadList = NULL; - strcpy( wads,wadstr ); + Q_strncpyz( wads, wadstr, sizeof( wads ) ); QE_ConvertDOSToUnixName( wads,wads ); // ok, we got the list of ; delimited wads, now split it into a GSList that contains @@ -81,7 +81,7 @@ void BuildWadList( char *wadstr ){ } if ( strchr( p1,'/' ) || strchr( p1,'\\' ) ) { - ExtractFileName( p1,cleanwadname ); + ExtractFileName( p1, cleanwadname, sizeof( cleanwadname ) ); trim( cleanwadname ); @@ -202,7 +202,7 @@ void Patch_Parse( patchMesh_t *pPatch ){ GetToken( true ); str = new char[strlen( token ) + 10]; strcpy( str, "textures/" ); - strcpy( str + 9, token ); + Q_strncpyz( str + 9, token, sizeof( str ) - 9 ); pPatch->pShader = QERApp_Shader_ForName( str ); pPatch->d_texture = pPatch->pShader->getTexture(); delete [] str; @@ -568,7 +568,7 @@ void Entity_Parse( entity_t *pEntity ){ } else { - strcpy( temptoken, token ); + Q_strncpyz( temptoken, token, sizeof( temptoken ) ); GetToken( false ); SetKeyValue( pEntity, temptoken, token ); diff --git a/plugins/mapxml/xmlwrite.cpp b/plugins/mapxml/xmlwrite.cpp index 583dc6f2..5ba6177d 100644 --- a/plugins/mapxml/xmlwrite.cpp +++ b/plugins/mapxml/xmlwrite.cpp @@ -77,9 +77,9 @@ void Patch_XMLWrite( patchMesh_t *pPatch, xmlNodePtr surface ){ node = xmlNewChild( surface, NULL, (xmlChar *)"matrix", (xmlChar *)str ); delete [] str; - sprintf( buf, "%i", pPatch->width ); + snprintf( buf, sizeof( buf ), "%i", pPatch->width ); xmlSetProp( node, (xmlChar *)"width", (xmlChar *)buf ); - sprintf( buf, "%i", pPatch->height ); + snprintf( buf, sizeof( buf ), "%i", pPatch->height ); xmlSetProp( node, (xmlChar *)"height", (xmlChar *)buf ); } @@ -108,15 +108,15 @@ void Face_XMLWrite( face_t *face, xmlNodePtr surface, bool bAlternateTexdef = fa if ( !bAlternateTexdef ) { // write texdef - sprintf( buf, "%i", (int)face->texdef.shift[0] ); + snprintf( buf, sizeof( buf ), "%i", (int)face->texdef.shift[0] ); str = str_append_token( NULL, buf ); - sprintf( buf, "%i", (int)face->texdef.shift[1] ); + snprintf( buf, sizeof( buf ), "%i", (int)face->texdef.shift[1] ); str = str_append_token( str, buf ); - sprintf( buf, "%i", (int)face->texdef.rotate ); + snprintf( buf, sizeof( buf ), "%i", (int)face->texdef.rotate ); str = str_append_token( str, buf ); - sprintf( buf, "%f", face->texdef.scale[0] ); + snprintf( buf, sizeof( buf ), "%f", face->texdef.scale[0] ); str = str_append_token( str, buf ); - sprintf( buf, "%f", face->texdef.scale[1] ); + snprintf( buf, sizeof( buf ), "%f", face->texdef.scale[1] ); str = str_append_token( str, buf ); node = xmlNewChild( surface, NULL, (xmlChar *)"texdef", (xmlChar *)str ); @@ -139,11 +139,11 @@ void Face_XMLWrite( face_t *face, xmlNodePtr surface, bool bAlternateTexdef = fa } // write flags - sprintf( buf, "%i", face->texdef.contents ); + snprintf( buf, sizeof( buf ), "%i", face->texdef.contents ); str = str_append_token( NULL, buf ); - sprintf( buf, "%i", face->texdef.flags ); + snprintf( buf, sizeof( buf ), "%i", face->texdef.flags ); str = str_append_token( str, buf ); - sprintf( buf, "%i", face->texdef.value ); + snprintf( buf, sizeof( buf ), "%i", face->texdef.value ); str = str_append_token( str, buf ); node = xmlNewChild( surface, NULL, (xmlChar *)"flags", (xmlChar *)str ); diff --git a/plugins/model/plugin.cpp b/plugins/model/plugin.cpp index e7c9c138..c136dbac 100644 --- a/plugins/model/plugin.cpp +++ b/plugins/model/plugin.cpp @@ -142,7 +142,7 @@ void init_filetypes(){ char buf[16]; buf[0] = '*'; buf[1] = '.'; - strcpy( buf + 2, *ext ); + Q_strncpyz( buf + 2, *ext, sizeof( buf ) - 2 ); GetFileTypeRegistry()->addType( MODEL_MAJOR, filetype_t( module->displayName, buf ) ); } } diff --git a/plugins/shaders/shaders.cpp b/plugins/shaders/shaders.cpp index f323294a..1d531a42 100644 --- a/plugins/shaders/shaders.cpp +++ b/plugins/shaders/shaders.cpp @@ -226,7 +226,7 @@ CPtrArray PatchShaders; void PushPatch( patchMesh_t * patch ){ patchEntry_t *pEntry = new patchEntry_s; pEntry->p = patch; - strcpy( pEntry->name, patch->pShader->getName() ); + Q_strncpyz( pEntry->name, patch->pShader->getName(), sizeof( pEntry->name ) ); PatchShaders.Add( pEntry ); } @@ -734,7 +734,7 @@ qtexture_t *WINAPI QERApp_Try_Texture_ForName( const char *name ){ } g_free( pPixels ); - strcpy( q->name, name ); + Q_strncpyz( q->name, name, sizeof( q->name ) ); // only strip extension if extension there is! if ( q->name[strlen( q->name ) - 4] == '.' ) { q->name[strlen( q->name ) - 4] = '\0'; @@ -792,7 +792,7 @@ void CShader::CreateColor( const char *name ){ // copy this one qtexture_t *q2 = new qtexture_t; memcpy( q2, q1, sizeof( qtexture_t ) ); - strcpy( q2->name, m_strTextureName.GetBuffer() ); + Q_strncpyz( q2->name, m_strTextureName.GetBuffer(), sizeof( q2->name ) ); VectorCopy( m_vColor, q2->color ); m_pTexture = q2; } diff --git a/plugins/surface/surfacedialog.cpp b/plugins/surface/surfacedialog.cpp index cbe7a5bd..d1c1471c 100644 --- a/plugins/surface/surfacedialog.cpp +++ b/plugins/surface/surfacedialog.cpp @@ -202,7 +202,7 @@ void IsFaceConflicting(){ tmp_texdef = &get_texdef_face_list()->texdef; - strcpy( texture_name, tmp_texdef->GetName() ); + Q_strncpyz( texture_name, tmp_texdef->GetName(), sizeof( texture_name ) ); texdef_SI_values.shift[0] = tmp_texdef->shift[0]; texdef_SI_values.shift[1] = tmp_texdef->shift[1]; @@ -297,14 +297,14 @@ static void PopulateTextureComboList(){ if ( texdef_face_list_empty() ) { items = g_list_append( items, (gpointer) blank ); // For Texture Entry, activate only on entry change - strcpy( old_texture_entry, blank ); + Q_strncpyz( old_texture_entry, blank, sizeof( old_texture_entry ) ); } else if ( !is_TextureName_conflicting ) { temp_texdef_face_list = get_texdef_face_list(); tmp_texdef = (texdef_t *) &get_texdef_face_list()->texdef; items = g_list_append( items, (gpointer) tmp_texdef->GetName() ); // For Texture Entry, activate only on entry change - strcpy( old_texture_entry, tmp_texdef->GetName() ); + Q_strncpyz( old_texture_entry, tmp_texdef->GetName(), sizeof( old_texture_entry ) ); } else { @@ -324,7 +324,7 @@ static void PopulateTextureComboList(){ // If this isn't added last (to the top of the list), g_list_find freaks. items = g_list_prepend( items, (gpointer) blank ); // For Texture Entry, activate only on entry change - strcpy( old_texture_entry, blank ); + Q_strncpyz( old_texture_entry, blank, sizeof( old_texture_entry ) ); } for( lst = items; lst != NULL; lst = g_list_next( lst ) ) @@ -1002,7 +1002,7 @@ void on_texture_combo_entry_activate( GtkEntry *entry, gpointer user_data ){ if ( !texdef_face_list_empty() && g_bListenChanged ) { // activate only on entry change - strcpy( text, gtk_entry_get_text( entry ) ); + Q_strncpyz( text, gtk_entry_get_text( entry ), sizeof( text ) ); if ( strcmp( old_texture_entry, text ) ) { // Check for spaces in shader name if ( text[0] <= ' ' || strchr( text, ' ' ) ) { @@ -1014,7 +1014,7 @@ void on_texture_combo_entry_activate( GtkEntry *entry, gpointer user_data ){ { tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef; tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef; - strcpy( old_texture_entry, text ); + Q_strncpyz( old_texture_entry, text, sizeof( old_texture_entry ) ); tmp_texdef->SetName( text ); } GetTexMods(); diff --git a/plugins/surface_idtech2/surfacedialog.cpp b/plugins/surface_idtech2/surfacedialog.cpp index be395773..6ceaa5de 100644 --- a/plugins/surface_idtech2/surfacedialog.cpp +++ b/plugins/surface_idtech2/surfacedialog.cpp @@ -161,7 +161,7 @@ void IsFaceConflicting(){ tmp_texdef = &get_texdef_face_list()->texdef; - strcpy( texture_name, tmp_texdef->GetName() ); + Q_strncpyz( texture_name, tmp_texdef->GetName(), sizeof( texture_name ) ); texdef_SI_values.shift[0] = tmp_texdef->shift[0]; texdef_SI_values.shift[1] = tmp_texdef->shift[1]; @@ -261,14 +261,14 @@ static void PopulateTextureComboList(){ if ( texdef_face_list_empty() ) { items = g_list_append( items, (gpointer) blank ); // For Texture Entry, activate only on entry change - strcpy( old_texture_entry, blank ); + Q_strncpyz( old_texture_entry, blank, sizeof( old_texture_entry ) ); } else if ( !is_TextureName_conflicting ) { temp_texdef_face_list = get_texdef_face_list(); tmp_texdef = (texdef_t *) &get_texdef_face_list()->texdef; items = g_list_append( items, (gpointer) tmp_texdef->GetName() ); // For Texture Entry, activate only on entry change - strcpy( old_texture_entry, tmp_texdef->GetName() ); + Q_strncpyz( old_texture_entry, tmp_texdef->GetName(), sizeof( old_texture_entry ) ); } else { @@ -288,7 +288,7 @@ static void PopulateTextureComboList(){ // If this isn't added last (to the top of the list), g_list_find freaks. items = g_list_prepend( items, (gpointer) blank ); // For Texture Entry, activate only on entry change - strcpy( old_texture_entry, blank ); + Q_strncpyz( old_texture_entry, blank, sizeof( old_texture_entry ) ); } for( lst = items; lst != NULL; lst = g_list_next( lst ) ) @@ -883,7 +883,7 @@ void on_texture_combo_entry_activate( GtkEntry *entry, gpointer user_data ){ if ( !texdef_face_list_empty() && g_bListenChanged ) { // activate only on entry change - strcpy( text, gtk_entry_get_text( entry ) ); + Q_strncpyz( text, gtk_entry_get_text( entry ), sizeof( text ) ); if ( strcmp( old_texture_entry, text ) ) { // Check for spaces in shader name if ( text[0] <= ' ' || strchr( text, ' ' ) ) { @@ -895,7 +895,7 @@ void on_texture_combo_entry_activate( GtkEntry *entry, gpointer user_data ){ { tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef; tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef; - strcpy( old_texture_entry, text ); + Q_strncpyz( old_texture_entry, text, sizeof( old_texture_entry ) ); tmp_texdef->SetName( text ); } GetTexMods(); diff --git a/plugins/surface_idtech2/surfaceflags.cpp b/plugins/surface_idtech2/surfaceflags.cpp index e16ec308..1affb160 100644 --- a/plugins/surface_idtech2/surfaceflags.cpp +++ b/plugins/surface_idtech2/surfaceflags.cpp @@ -163,7 +163,7 @@ void set_surface_flags_button_state( texdef_to_face_t *texdef_face_list, bool b_ } else { working_value = value; - sprintf( tex_buff, "%d", value ); + snprintf( tex_buff, sizeof( tex_buff ), "%d", value ); gtk_entry_set_text( (GtkEntry *)value_entry, tex_buff ); } diff --git a/plugins/vfspak/vfs.cpp b/plugins/vfspak/vfs.cpp index d12b6240..364a45e4 100644 --- a/plugins/vfspak/vfs.cpp +++ b/plugins/vfspak/vfs.cpp @@ -193,7 +193,7 @@ static GSList* vfsGetListInternal( const char *dir, const char *ext, bool direct dirlen = strlen( dirname ); if ( ext != NULL ) { - strcpy( extension, ext ); + Q_strncpyz( extension, ext, sizeof( extension ) ); } else{ extension[0] = '\0'; @@ -650,7 +650,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ } vfsCleanFileName( l_in ); #else - strcpy( l_in, in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); vfsCleanFileName( l_in ); #endif // ifdef WIN32 diff --git a/plugins/vfspk3/vfs.cpp b/plugins/vfspk3/vfs.cpp index d8b1c0fa..e4f6e246 100644 --- a/plugins/vfspk3/vfs.cpp +++ b/plugins/vfspk3/vfs.cpp @@ -686,7 +686,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ } vfsCleanFileName( l_in ); #else - strcpy( l_in, in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); vfsCleanFileName( l_in ); #endif // ifdef WIN32 diff --git a/plugins/vfswad/vfs.cpp b/plugins/vfswad/vfs.cpp index e0d2a445..6afa6289 100644 --- a/plugins/vfswad/vfs.cpp +++ b/plugins/vfswad/vfs.cpp @@ -116,7 +116,7 @@ int vfsBuildShortPathName( const char* pPath, char* pBuffer, int nBufferLen ){ int nResult = GetFullPathName( pPath, nBufferLen, pBuffer, &pFile ); nResult = GetShortPathName( pPath, pBuffer, nBufferLen ); if ( nResult == 0 ) { - strcpy( pBuffer, pPath ); // Use long filename + Q_strncpyz( pBuffer, pPath, nBufferLen ); // Use long filename } return nResult; #endif @@ -162,7 +162,7 @@ static void vfsInitPakFile( const char *filename ){ for ( i = strlen( filename ) - 1 ; i >= 0 && filename[i] != '\\' && filename[i] != '/' ; i-- ) wadnameptr = (char *)filename + i; - strcpy( wadname,wadnameptr ); + Q_strncpyz( wadname, wadnameptr, sizeof( wadname ) ); wadname[strlen( wadname ) - 4] = 0; // ditch the .wad so everthing looks nice! strlwr( wadname ); @@ -221,7 +221,7 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir int i; if ( refdir != NULL ) { - strcpy( dirname, refdir ); + Q_strncpyz( dirname, refdir, sizeof( dirname ) ); strlwr( dirname ); vfsFixDOSName( dirname ); vfsAddSlash( dirname, sizeof( dirname ) ); @@ -232,7 +232,7 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir dirlen = strlen( dirname ); if ( ext != NULL ) { - strcpy( extension, ext ); + Q_strncpyz( extension, ext, sizeof( extension ) ); } else{ extension[0] = '\0'; @@ -366,7 +366,7 @@ void vfsInitDirectory( const char *path ){ return; } - strcpy( g_strDirs[g_numDirs], path ); + Q_strncpyz( g_strDirs[g_numDirs], path, sizeof( g_strDirs[g_numDirs] ) ); vfsFixDOSName( g_strDirs[g_numDirs] ); vfsAddSlash( g_strDirs[g_numDirs], sizeof( g_strDirs[g_numDirs] ) ); g_numDirs++; @@ -450,7 +450,7 @@ int vfsGetFileCount( const char *filename, int flag ){ char fixed[NAME_MAX], tmp[NAME_MAX]; GSList *lst; - strcpy( fixed, filename ); + Q_strncpyz( fixed, filename, sizeof( fixed ) ); vfsFixDOSName( fixed ); strlwr( fixed ); @@ -514,7 +514,7 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){ GSList *lst; *bufferptr = NULL; - strcpy( fixed, filename ); + Q_strncpyz( fixed, filename, sizeof( fixed ) ); vfsFixDOSName( fixed ); strlwr( fixed ); @@ -633,8 +633,8 @@ char* vfsExtractRelativePath( const char *in ){ Sys_Printf( "vfsExtractRelativePath: %s\n", in ); #endif - strcpy( l_in,in ); - vfsCleanFileName( l_in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); + vfsCleanFileName( l_in, sizeof( l_in ) ); #ifdef DBG_RLTPATH Sys_Printf( "cleaned path: %s\n", l_in ); @@ -642,15 +642,15 @@ char* vfsExtractRelativePath( const char *in ){ for ( i = 0; i < g_numDirs; i++ ) { - strcpy( check,g_strDirs[i] ); - vfsCleanFileName( check ); + Q_strncpyz( check, g_strDirs[i], sizeof( check ) ); + vfsCleanFileName( check, sizeof( check ) ); #ifdef DBG_RLTPATH Sys_Printf( "Matching against %s\n", check ); #endif // try to find a match if ( strstr( l_in, check ) ) { - strcpy( out,l_in + strlen( check ) + 1 ); + Q_strncpyz( out, l_in + strlen( check ) + 1, sizeof( out ) ); break; } } @@ -667,7 +667,7 @@ char* vfsExtractRelativePath( const char *in ){ } // removed CString usage -void vfsCleanFileName( char *in ){ +void vfsCleanFileName( char *in, size_t length ){ char str[PATH_MAX]; vfsBuildShortPathName( in, str, PATH_MAX ); strlwr( str ); @@ -676,7 +676,7 @@ void vfsCleanFileName( char *in ){ if ( str[n - 1] == '/' ) { str[n - 1] = '\0'; } - strcpy( in, str ); + Q_strncpyz( in, str, length ); } // HYDRA: this now searches VFS/PAK files in addition to the filesystem @@ -694,7 +694,7 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ char fixed[NAME_MAX]; GSList *lst; - strcpy( fixed, in ); + Q_strncpyz( fixed, in, sizeof( fixed ) ); vfsFixDOSName( fixed ); strlwr( fixed ); @@ -723,7 +723,7 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ strncat( tmp, in, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { if ( count == index ) { - strcpy( out, tmp ); + Q_strncpyz( out, tmp, sizeof( out ) ); return out; } count++; diff --git a/plugins/vfswad/vfs.h b/plugins/vfswad/vfs.h index 942f456a..62be917a 100644 --- a/plugins/vfswad/vfs.h +++ b/plugins/vfswad/vfs.h @@ -51,7 +51,7 @@ int vfsLoadFullPathFile( const char *filename, void **buffer ); // on win32, will build the short path name // directories will be cleaned, no ending filename seperator // we modify the entry directly, the size of the string can only go down -void vfsCleanFileName( char * ); +void vfsCleanFileName( char *, size_t ); // these return a static char*, doesn't need to be freed or anything // get the base path to use when raising file dialogs // we manually add "maps/" or "sounds/" or "mapobjects/models/" etc. diff --git a/radiant/brush.cpp b/radiant/brush.cpp index 7cef07d6..e23a0e66 100644 --- a/radiant/brush.cpp +++ b/radiant/brush.cpp @@ -37,7 +37,7 @@ const char* Brush_Name( brush_t *b ){ static char cBuff[1024]; b->numberId = g_nBrushId++; if ( g_qeglobals.m_bBrushPrimitMode ) { - sprintf( cBuff, "Brush %i", b->numberId ); + snprintf( cBuff, sizeof( cBuff ), "Brush %i", b->numberId ); Brush_SetEpair( b, "Name", cBuff ); } return cBuff; diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index 0d12037d..c00a3073 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -228,7 +228,7 @@ void Dialog::UpdateData( bool retrieve ){ gtk_entry_set_text( GTK_ENTRY( data->object ), buf ); break; case DLG_ENTRY_INT: - sprintf( buf, "%d", ( *(int*)data->buffer ) ); + snprintf( buf, sizeof( buf ), "%d", ( *(int*)data->buffer ) ); gtk_entry_set_text( GTK_ENTRY( data->object ), buf ); break; case DLG_SPIN_FLOAT: diff --git a/radiant/drag.cpp b/radiant/drag.cpp index a6c2bf0d..3e3ae82e 100644 --- a/radiant/drag.cpp +++ b/radiant/drag.cpp @@ -282,14 +282,14 @@ void UpdateTarget( vec3_t origin, vec3_t dir ){ i = IntForKey( pe, "target" ); if ( i <= 0 ) { i = GetUniqueTargetId( 1 ); - sprintf( sz, "%d", i ); + snprintf( sz, sizeof( sz ), "%d", i ); SetKeyValue( pe, "target", sz ); } // set the target # into our src - sprintf( sz, "%d", i ); + snprintf( sz, sizeof( sz ), "%d", i ); SetKeyValue( peLink, "targetname", sz ); Sys_UpdateWindows( W_ENTITY ); diff --git a/radiant/eclass.cpp b/radiant/eclass.cpp index 926a025b..720ca351 100644 --- a/radiant/eclass.cpp +++ b/radiant/eclass.cpp @@ -227,7 +227,7 @@ void Eclass_CreateSpriteModelPaths(){ { // strip the path/ and the .extension. - ExtractFileBase( (char *)pFile->data,filename ); + ExtractFileBase( (char *)pFile->data, filename, sizeof( filename ) ); // does the eclass name match the filename? if ( stricmp( e->name,filename ) == 0 ) { @@ -297,7 +297,7 @@ eclass_t * EClass_Create( const char *name, float col1, float col2, float col3, e->color[0] = col1; e->color[1] = col2; e->color[2] = col3; - sprintf( color, "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); + snprintf( color, sizeof( color ), "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); e->texdef.SetName( color ); // supplied size ? diff --git a/radiant/eclass_def.cpp b/radiant/eclass_def.cpp index 7d428d49..ef9415c2 100644 --- a/radiant/eclass_def.cpp +++ b/radiant/eclass_def.cpp @@ -144,7 +144,7 @@ eclass_t *Eclass_InitFromText( char *text ){ if ( r != 3 ) { return e; } - sprintf( color, "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); + snprintf( color, sizeof( color ), "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); //strcpy (e->texdef.name, color); e->texdef.SetName( color ); diff --git a/radiant/groupdialog.cpp b/radiant/groupdialog.cpp index ac8889e1..acbb8a38 100644 --- a/radiant/groupdialog.cpp +++ b/radiant/groupdialog.cpp @@ -202,7 +202,7 @@ void GetSpawnFlags( void ){ } else { - sprintf( sz, "%i", f ); + snprintf( sz, sizeof( sz ), "%i", f ); if ( multiple_entities ) { brush_t *b; diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 02e8df9f..e0995d58 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -1013,7 +1013,7 @@ void DoMapInfo(){ { entry = (map_t*)entitymap->data; char tmp[16]; - sprintf( tmp, "%d", entry->count ); + snprintf( tmp, sizeof( tmp ), "%d", entry->count ); GtkTreeIter iter; gtk_list_store_append( GTK_LIST_STORE( store ), &iter ); gtk_list_store_set( GTK_LIST_STORE( store ), &iter, 0, tmp, 1, entry->name, -1 ); @@ -1022,11 +1022,11 @@ void DoMapInfo(){ } char tmp[16]; - sprintf( tmp, "%d", TotalBrushes ); + snprintf( tmp, sizeof( tmp ), "%d", TotalBrushes ); gtk_label_set_text( GTK_LABEL( brushes_label ), tmp ); - sprintf( tmp, "%d", TotalEntities ); + snprintf( tmp, sizeof( tmp ), "%d", TotalEntities ); gtk_label_set_text( GTK_LABEL( entities_label ), tmp ); - sprintf( tmp, "%d", Net ); + snprintf( tmp, sizeof( tmp ), "%d", Net ); gtk_label_set_text( GTK_LABEL( net_label ), tmp ); response_id = gtk_dialog_run( GTK_DIALOG( dialog ) ); @@ -2740,7 +2740,7 @@ int DoBSInputDlg( const char *fields[5], float values[5] ){ gtk_widget_show( entries[i] ); char buf[64]; - sprintf( buf, "%f", values[i] ); + snprintf( buf, sizeof( buf ), "%f", values[i] ); gtk_entry_set_text( GTK_ENTRY( entries[i] ), buf ); } diff --git a/radiant/main.cpp b/radiant/main.cpp index f67602b0..fa68c74e 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -182,11 +182,11 @@ int loki_getmountpoint( const char *device, char *mntpt, int max_size ){ { char *tmp, mntdev[1024]; - strcpy( mntdev, mntent->mnt_fsname ); + Q_strncpyz( mntdev, mntent->mnt_fsname, sizeof( mntdev ) ); if ( strcmp( mntent->mnt_type, "supermount" ) == 0 ) { tmp = strstr( mntent->mnt_opts, "dev=" ); if ( tmp ) { - strcpy( mntdev, tmp + strlen( "dev=" ) ); + Q_strcnpyz( mntdev, tmp + strlen( "dev=" ), sizeof( mntdev ) ); tmp = strchr( mntdev, ',' ); if ( tmp ) { *tmp = '\0'; @@ -947,7 +947,7 @@ void QE_ExpandBspString( char *bspaction, GPtrArray *out_array, char *mapname ){ } else { - ExtractFileName( mapname, base ); + ExtractFileName( mapname, base, sizeof( base ) ); } // this important step alters the map name to add fs_game @@ -1143,7 +1143,7 @@ void RunBsp( char *command ){ if ( g_PrefsDlg.m_bWatchBSP ) { // grab the file name for engine running char *bspname = new char[1024]; - ExtractFileName( currentmap, bspname ); + ExtractFileName( currentmap, bspname, sizeof( bspname ) ); StripExtension( bspname ); g_pParentWnd->GetWatchBSP()->DoMonitoringLoop( sys, bspname ); } else { diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index cedf14ae..ef64405c 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -3958,7 +3958,7 @@ void MainFrame::UpdateWindows( int nBits ){ #ifdef DBG_WINDOWPOS static int bean_count = 0; char bean_buf[100]; - sprintf( bean_buf,"UpdateWindows %d",bean_count ); + snprintf( bean_buf, sizeof( bean_buf ), "UpdateWindows %d", bean_count ); CheckWatchit( bean_buf ); bean_count++; #endif @@ -3993,7 +3993,7 @@ void MainFrame::UpdateWindows( int nBits ){ } } #ifdef DBG_WINDOWPOS - sprintf( bean_buf,"%d (end UpdateWidows)",bean_count ); + snprintf( bean_buf, sizeof( bean_buf ), "%d (end UpdateWidows)", bean_count ); CheckWatchit( bean_buf ); #endif } @@ -4002,7 +4002,7 @@ void MainFrame::RoutineProcessing(){ #ifdef DBG_WINDOWPOS static int bean_count = 0; char bean_buf[100]; - sprintf( bean_buf,"RoutineProcessing %d",bean_count ); + snprintf( bean_buf, sizeof( bean_buf ), "RoutineProcessing %d", bean_count ); CheckWatchit( bean_buf ); bean_count++; #endif @@ -4079,7 +4079,7 @@ void MainFrame::RoutineProcessing(){ */ } #ifdef DBG_WINDOWPOS - sprintf( bean_buf,"%d (end RoutineProcessing)",bean_count ); + snprintf( bean_buf, sizeof( bean_buf ), "%d (end RoutineProcessing)", bean_count ); CheckWatchit( bean_buf ); #endif } @@ -6243,7 +6243,7 @@ void MainFrame::OnMiscSelectentitycolor(){ if ( inspector_mode == W_ENTITY && ( DoColor( COLOR_ENTITY ) ) ) { char buffer[256]; - sprintf( buffer, "%f %f %f", g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][0], + snprintf( buffer, sizeof( buffer ), "%f %f %f", g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][0], g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][1], g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][2] ); diff --git a/radiant/map.cpp b/radiant/map.cpp index 542ab342..972bbfc4 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -830,7 +830,7 @@ void Map_New( void ){ Sys_Printf( "Map_New\n" ); Map_Free(); - strcpy( currentmap, "unnamed.map" ); + Q_strncpyz( currentmap, "unnamed.map", sizeof( currentmap ) ); Sys_SetTitle( currentmap ); world_entity = (entity_s*)qmalloc( sizeof( *world_entity ) ); @@ -932,9 +932,9 @@ void AddRegionBrushes( void ){ SetKeyValue( region_startpoint, "classname", "info_player_start" ); region_startpoint->eclass = Eclass_ForName( "info_player_start", false ); char sTmp[1024]; - sprintf( sTmp, "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] ); + snprintf( sTmp, sizeof( sTmp ), "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] ); SetKeyValue( region_startpoint, "origin", sTmp ); - sprintf( sTmp, "%d", (int)g_pParentWnd->GetCamWnd()->Camera()->angles[YAW] ); + snprintf( sTmp, sizeof( sTmp ), "%d", (int)g_pParentWnd->GetCamWnd()->Camera()->angles[YAW] ); SetKeyValue( region_startpoint, "angle", sTmp ); // empty array of children region_startpoint->pData = new CPtrArray; diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index b0de2f5f..584c671d 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -229,7 +229,7 @@ void WindowPosition_Parse( window_position_t& m_value, const CString& value ){ void WindowPosition_Write( const window_position_t& m_value, CString& value ){ char buffer[64]; - sprintf( buffer, "%d %d %d %d", m_value.x, m_value.y, m_value.w, m_value.h ); + snprintf( buffer, sizeof( buffer ), "%d %d %d %d", m_value.x, m_value.y, m_value.w, m_value.h ); value = buffer; } @@ -308,7 +308,7 @@ void CXMLPropertyBag::GetPref( const char *name, int *pV, int V ){ else { char s[12]; - sprintf( s, "%d", V ); + snprintf( s, sizeof( s ), "%d", V ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); *pV = V; @@ -348,7 +348,7 @@ void CXMLPropertyBag::GetPref( const char *name, float *pV, float V ){ else { char s[64]; - sprintf( s, "%f", V ); + snprintf( s, sizeof( s ), "%f", V ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); *pV = V; @@ -365,7 +365,7 @@ void CXMLPropertyBag::GetPref( const char *name, float* pV, float* V ){ else { char s[256]; - sprintf( s, "%f %f %f", V[0], V[1], V[2] ); + snprintf( s, sizeof( s ), "%f %f %f", V[0], V[1], V[2] ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); pV[0] = V[0]; @@ -416,11 +416,11 @@ void CXMLPropertyBag::UpdatePrefTree(){ xmlNodeSetContent( pNode, (const xmlChar *)( (Str *)pPref->mVal )->GetBuffer() ); break; case PREF_INT: - sprintf( s, "%d", *(int *)pPref->mVal ); + snprintf( s, sizeof( s ), "%d", *(int *)pPref->mVal ); xmlNodeSetContent( pNode, (xmlChar *)s ); break; case PREF_FLOAT: - sprintf( s, "%f", *(float *)pPref->mVal ); + snprintf( s, sizeof( s ), "%f", *(float *)pPref->mVal ); xmlNodeSetContent( pNode, (xmlChar *)s ); break; case PREF_BOOL: @@ -430,7 +430,7 @@ void CXMLPropertyBag::UpdatePrefTree(){ case PREF_VEC3: { float* v = (float*)pPref->mVal; - sprintf( s, "%f %f %f", v[0], v[1], v[2] ); + snprintf( s, sizeof( s ), "%f %f %f", v[0], v[1], v[2] ); xmlNodeSetContent( pNode, (xmlChar *)s ); } break; @@ -849,7 +849,7 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const Str &GameFile ){ aux_path[strlen( aux_path ) - 1] = '\0'; // strip ending '/' if any } char up_path[PATH_MAX]; // up one level - ExtractFilePath( aux_path, up_path ); + ExtractFilePath( aux_path, up_path, sizeof( up_path ) ); mEnginePath = up_path; } } @@ -3044,7 +3044,7 @@ void PrefsDlg::LoadPrefs(){ for ( i = 0; i < 4; i++ ) { char buf[64]; - sprintf( buf, "%s%d", FILE_KEY, i ); + snprintf( buf, sizeof( buf ), "%s%d", FILE_KEY, i ); mLocalPrefs.GetPref( buf, &m_strMRUFiles[i], "" ); } @@ -3087,7 +3087,7 @@ void PrefsDlg::LoadPrefs(){ for ( i = 0; i < 3; i++ ) { char buf[64]; - sprintf( buf, "%s%d", SI_AXISCOLORS_KEY, i ); + snprintf( buf, sizeof( buf ), "%s%d", SI_AXISCOLORS_KEY, i ); mLocalPrefs.GetPref( buf, g_qeglobals.d_savedinfo.AxisColors[i], vDefaultAxisColours[i] ); } @@ -3111,7 +3111,7 @@ void PrefsDlg::LoadPrefs(){ for ( i = 0; i < COLOR_LAST; i++ ) { char buf[64]; - sprintf( buf, "%s%d", SI_COLORS_KEY, i ); + snprintf( buf, sizeof( buf ), "%s%d", SI_COLORS_KEY, i ); mLocalPrefs.GetPref( buf, g_qeglobals.d_savedinfo.colors[i], vDefaultColours[i] ); } diff --git a/radiant/profile.cpp b/radiant/profile.cpp index df645ce0..acbb9ead 100644 --- a/radiant/profile.cpp +++ b/radiant/profile.cpp @@ -187,13 +187,13 @@ static bool save_var( const char *filename, const char *section, const char *key bool WINAPI profile_save_int( const char *filename, const char *section, const char *key, int value ){ char buf[16]; - sprintf( buf, "%d", value ); + snprintf( buf, sizeof( buf ), "%d", value ); return save_var( filename, section, key, buf ); } bool WINAPI profile_save_float( const char *filename, const char *section, const char *key, float value ){ char buf[64]; - sprintf( buf, "%f", value ); + snprintf( buf, sizeof( buf ), "%f", value ); return save_var( filename, section, key, buf ); } diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index c512ea67..45a57dd3 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -598,8 +598,9 @@ bool QE_LoadProject( const char *projectfile ){ int ver = IntForKey( g_qeglobals.d_project_entity, "version" ); if ( ver > PROJECT_VERSION ) { char strMsg[1024]; - sprintf( strMsg, "This is a version %d project file. This build only supports <=%d project files.\n" - "Please choose another project file or upgrade your version of Radiant.", ver, PROJECT_VERSION ); + snprintf( strMsg, sizeof( strMsg ), + "This is a version %d project file. This build only supports <=%d project files.\n" + "Please choose another project file or upgrade your version of Radiant.", ver, PROJECT_VERSION ); gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg, "Can't load project file", MB_ICONERROR | MB_OK ); // set the project file to nothing so we are sure we'll ask next time? g_PrefsDlg.m_strLastProject = ""; @@ -1358,7 +1359,7 @@ void Sys_UpdateStatusBar( void ){ char numbrushbuffer[100] = ""; - sprintf( numbrushbuffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities ); + snprintf( numbrushbuffer, sizeof( numbrushbuffer ), "Brushes: %d Entities: %d", g_numbrushes, g_numentities ); g_pParentWnd->SetStatusText( 2, numbrushbuffer ); //Sys_Status( numbrushbuffer, 2 ); } @@ -1397,7 +1398,7 @@ static void MRU_SetText( int index, const char *filename ){ char mnemonic[PATH_MAX * 2 + 4]; mnemonic[0] = '_'; - sprintf( mnemonic + 1, "%d", index + 1 ); + snprintf( mnemonic + 1, sizeof( mnemonic ) - 1, "%d", index + 1 ); mnemonic[2] = '-'; mnemonic[3] = ' '; buffer_write_escaped_mnemonic( mnemonic + 4, filename ); diff --git a/radiant/select.cpp b/radiant/select.cpp index de8ea82e..86cad631 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -755,7 +755,7 @@ void Select_ApplyMatrix( bool bSnap, bool bRotation, int nAxis, float fDeg ){ // // update the origin key char text[64]; - sprintf( text, "%i %i %i", + snprintf( text, sizeof( text ), "%i %i %i", (int)b->owner->origin[0], (int)b->owner->origin[1], (int)b->owner->origin[2] ); SetKeyValue( b->owner, "origin", text ); diff --git a/radiant/targetname.cpp b/radiant/targetname.cpp index 84461afd..cecea044 100644 --- a/radiant/targetname.cpp +++ b/radiant/targetname.cpp @@ -47,7 +47,7 @@ void Entity_Connect( entity_t *e1, entity_t *e2 ){ } } } - sprintf( newtarget, "t%i", maxtarget + 1 ); + snprintf( newtarget, sizeof( newtarget ), "t%i", maxtarget + 1 ); #ifdef _DEBUG Sys_Printf( "Connecting entities with new target/targetname: %s\n", newtarget ); diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 00c99b34..6fd28202 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -738,7 +738,7 @@ void FillTextureList( GSList** pArray ) char shaderfile[PATH_MAX]; gboolean found = FALSE; - ExtractFileName( (char*)l_shaderfiles->data, shaderfile ); + ExtractFileName( (char*)l_shaderfiles->data, shaderfile, sizeof( shaderfile ) ); StripExtension( shaderfile ); strlwr( shaderfile ); @@ -966,7 +966,7 @@ void Texture_ShowDirectory(){ ============== */ void Texture_ShowDirectory( int menunum ){ - strcpy( texture_directory, texture_menunames[menunum - CMD_TEXTUREWAD] ); + Q_strncpyz( texture_directory, texture_menunames[menunum - CMD_TEXTUREWAD], sizeof( texture_directory ) ); Texture_ShowDirectory(); } @@ -1046,7 +1046,7 @@ void Texture_ShowAll(){ QERApp_ActiveShaders_SetDisplayed( true ); g_bShowAllShaders = true; // put some information in the texture window title? - sprintf( name, "Textures: in use" ); + snprintf( name, sizeof( name ), "Textures: in use" ); gtk_window_set_title( GTK_WINDOW( g_qeglobals_gui.d_entity ), name ); Sys_UpdateWindows( W_TEXTURE ); } @@ -1101,7 +1101,7 @@ void WINAPI Texture_ShowInuse( void ){ // we are no longer showing everything g_bShowAllShaders = false; // put some information in the texture window title? - sprintf( name, "Textures: in use" ); + snprintf( name, sizeof( name ), "Textures: in use" ); gtk_window_set_title( GTK_WINDOW( g_qeglobals_gui.d_entity ), name ); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 6d050ba8..e1770b3c 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -407,7 +407,7 @@ void CreateEntityFromName( const char* name, const vec3_t origin ){ if ( DoLightIntensityDlg( &intensity ) == IDOK ) { g_PrefsDlg.m_iLastLightIntensity = intensity; char buf[30]; - sprintf( buf, "255 255 255 %d", intensity ); + snprintf( buf, sizeof( buf ), "255 255 255 %d", intensity ); SetKeyValue( e, "_light", buf ); } } @@ -424,7 +424,7 @@ void CreateEntityFromName( const char* name, const vec3_t origin ){ if ( DoLightIntensityDlg( &intensity ) == IDOK ) { g_PrefsDlg.m_iLastLightIntensity = intensity; char buf[12]; - sprintf( buf, "%d", intensity ); + snprintf( buf, sizeof( buf ), "%d", intensity ); SetKeyValue( e, "light", buf ); } } @@ -2263,14 +2263,14 @@ void XYWnd::XY_DrawGrid(){ // This renders the numbers along varying X on top of the grid view (labels vertical grid lines). for ( x = xb - ( (int) xb ) % stepx; x <= xe; x += stepx ) { qglRasterPos2f( x + leftCushion, yPosLabelsTop ); - sprintf( text, "%i", (int) x ); + snprintf( text, sizeof( text ), "%i", (int) x ); gtk_glwidget_print_string( text ); } // This renders the numbers along varying Y on the left of the grid view (labels horizontal grid lines). for ( y = yb - ( (int) yb ) % stepy; y <= ye; y += stepy ) { qglRasterPos2f( xPosLabelsLeft, y + bottomOffset ); - sprintf( text, "%i", (int) y ); + snprintf( text, sizeof( text ), "%i", (int) y ); gtk_glwidget_print_string( text ); } @@ -2432,7 +2432,7 @@ void XYWnd::XY_DrawBlockGrid(){ for ( y = yb ; y < ye ; y += g_qeglobals.blockSize ) { qglRasterPos2f( x + ( g_qeglobals.blockSize / 2 ), y + ( g_qeglobals.blockSize / 2 ) ); - sprintf( text, "%i,%i",(int)floor( x / g_qeglobals.blockSize ), (int)floor( y / g_qeglobals.blockSize ) ); + snprintf( text, sizeof( text ), "%i,%i",(int)floor( x / g_qeglobals.blockSize ), (int)floor( y / g_qeglobals.blockSize ) ); gtk_glwidget_print_string( text ); } } diff --git a/radiant/z.cpp b/radiant/z.cpp index 90d373a2..d1455c8e 100644 --- a/radiant/z.cpp +++ b/radiant/z.cpp @@ -254,7 +254,7 @@ void Z_DrawGrid( void ){ for ( zz = zb ; zz < ze ; zz += step ) { qglRasterPos2f( -w + ( 1 / z.scale ), zz ); - sprintf( text, "%i",(int)zz ); + snprintf( text, sizeof( text ), "%i",(int)zz ); gtk_glwidget_print_string( text ); } } diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index bd184433..d7bac14e 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -120,7 +120,7 @@ void ExpandWildcards( int *argc, char ***argv ){ return; } - ExtractFilePath( path, filebase ); + ExtractFilePath( path, filebase, sizeof( filebase ) ); do { @@ -747,8 +747,9 @@ void StripExtension( char *path ){ */ // FIXME: should include the slash, otherwise // backing to an empty path will be wrong when appending a slash -void ExtractFilePath( const char *path, char *dest ){ +void ExtractFilePath( const char *path, char *dest, size_t size ){ const char *src; + size_t length; src = path + strlen( path ) - 1; @@ -758,13 +759,20 @@ void ExtractFilePath( const char *path, char *dest ){ while ( src != path && *( src - 1 ) != '\\' && *( src - 1 ) != '/' ) src--; - memcpy( dest, path, src - path ); - dest[src - path] = 0; + length = src - path; + if( length + 1 > size ) + { + length = size - 1; + } + memcpy( dest, path, length ); + dest[length] = 0; } -void ExtractFileBase( const char *path, char *dest ){ +void ExtractFileBase( const char *path, char *dest, size_t size ){ const char *src; + if( size <= 0 ) + return; src = path + strlen( path ) - 1; // @@ -775,12 +783,18 @@ void ExtractFileBase( const char *path, char *dest ){ while ( *src && *src != '.' ) { + if( size == 1 ) + { + *dest = 0; + return; + } *dest++ = *src++; + size--; } *dest = 0; } -void ExtractFileExtension( const char *path, char *dest, size_t length ){ +void ExtractFileExtension( const char *path, char *dest, size_t size ){ const char *src; src = path + strlen( path ) - 1; @@ -795,7 +809,7 @@ void ExtractFileExtension( const char *path, char *dest, size_t length ){ return; } - Q_strncpyz( dest, src, length ); + Q_strncpyz( dest, src, size ); } diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index b90308cd..9697d01f 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -119,9 +119,9 @@ void DefaultPath( char *path, const char *basepath ); void StripFilename( char *path ); void StripExtension( char *path ); -void ExtractFilePath( const char *path, char *dest ); -void ExtractFileBase( const char *path, char *dest ); -void ExtractFileExtension( const char *path, char *dest, size_t length ); +void ExtractFilePath( const char *path, char *dest, size_t size ); +void ExtractFileBase( const char *path, char *dest, size_t size ); +void ExtractFileExtension( const char *path, char *dest, size_t size ); int ParseNum( const char *str ); diff --git a/tools/quake3/common/inout.c b/tools/quake3/common/inout.c index d998ce18..d8ac4101 100644 --- a/tools/quake3/common/inout.c +++ b/tools/quake3/common/inout.c @@ -72,7 +72,7 @@ xmlNodePtr xml_NodeForVec( vec3_t v ){ xmlNodePtr ret; char buf[1024]; - sprintf( buf, "%f %f %f", v[0], v[1], v[2] ); + snprintf( buf, sizeof( buf ), "%f %f %f", v[0], v[1], v[2] ); ret = xmlNewNode( NULL, "point" ); xmlNodeSetContent( ret, buf ); return ret; @@ -157,7 +157,7 @@ void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ){ level[1] = 0; xmlSetProp( node, "level", (char *)&level ); // a 'select' information - sprintf( buf, "%i %i", entitynum, brushnum ); + snprintf( buf, sizeof( buf ), "%i %i", entitynum, brushnum ); select = xmlNewNode( NULL, "brush" ); xmlNodeSetContent( select, buf ); xmlAddChild( node, select ); @@ -208,7 +208,7 @@ void xml_Winding( char *msg, vec3_t p[], int numpoints, qboolean die ){ level[1] = 0; xmlSetProp( node, "level", (char *)&level ); // a 'winding' node - sprintf( buf, "%i ", numpoints ); + snprintf( buf, sizeof( buf ), "%i ", numpoints ); for ( i = 0; i < numpoints; i++ ) { snprintf( smlbuf, sizeof( smlbuf ), "(%g %g %g)", p[i][0], p[i][1], p[i][2] ); @@ -246,7 +246,7 @@ void Broadcast_Setup( const char *dest ){ brdcst_socket = Net_Connect( &address, 0 ); if ( brdcst_socket ) { // send in a header - sprintf( sMsg, "" ); + snprintf( sMsg, sizeof( sMsg ), "" ); NMSG_Clear( &msg ); NMSG_WriteString( &msg, sMsg ); Net_Send( brdcst_socket, &msg ); diff --git a/tools/quake3/q3data/3dslib.c b/tools/quake3/q3data/3dslib.c index f505d253..48894414 100644 --- a/tools/quake3/q3data/3dslib.c +++ b/tools/quake3/q3data/3dslib.c @@ -151,50 +151,50 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat if ( mat.texture[0] ) { snprintf( buffer, sizeof( buffer ), "%s%s", curdir, mat.texture ); if ( strstr( buffer, gamedir + 1 ) ) { - strcpy( mat.texture, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1 ); + Q_strncpyz( mat.texture, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1, sizeof( mat.texture ) ); } else{ - strcpy( mat.texture, buffer ); + Q_strncpyz( mat.texture, buffer, sizeof( mat.texture ) ); } } if ( mat.specular[0] ) { snprintf( buffer, sizeof( buffer ), "%s%s", curdir, mat.specular ); if ( strstr( buffer, gamedir + 1 ) ) { - strcpy( mat.specular, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1 ); + Q_strncpyz( mat.specular, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1, sizeof( mat.specular ) ); } else{ - strcpy( mat.specular, buffer ); + Q_strncpyz( mat.specular, buffer, sizeof( mat.specular ) ); } } if ( mat.bump[0] ) { snprintf( buffer, sizeof( buffer ), "%s%s", curdir, mat.bump ); if ( strstr( buffer, gamedir + 1 ) ) { - strcpy( mat.bump, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1 ); + Q_strncpyz( mat.bump, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1, sizeof( mat.bump ) ); } else{ - strcpy( mat.bump, buffer ); + Q_strncpyz( mat.bump, buffer, sizeof( mat.bump ) ); } } if ( mat.reflection[0] ) { snprintf( buffer, sizeof( buffer ), "%s%s", curdir, mat.reflection ); if ( strstr( buffer, gamedir + 1 ) ) { - strcpy( mat.reflection, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1 ); + Q_strncpyz( mat.reflection, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1, sizeof( mat.reflection ) ); } else{ - strcpy( mat.reflection, buffer ); + Q_strncpyz( mat.reflection, buffer, sizeof( mat.reflection ) ); } } if ( mat.opacity[0] ) { snprintf( buffer, sizeof( buffer ), "%s%s", curdir, mat.opacity ); if ( strstr( buffer, gamedir + 1 ) ) { - strcpy( mat.opacity, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1 ); + Q_strncpyz( mat.opacity, strstr( buffer, gamedir + 1 ) + strlen( gamedir ) - 1, sizeof( mat.opacity ) ); } else{ - strcpy( mat.opacity, buffer ); + Q_strncpyz( mat.opacity, buffer, sizeof( mat.opacity ) ); } } @@ -382,7 +382,7 @@ static void LoadNamedObject( FILE *fp, long thisChunkLen, _3DSNamedObject_t *pNO } } - strcpy( pNO->name, name ); + Q_strncpyz( pNO->name, name, sizeof( pNO->name ) ); pNO->pTriObjects = malloc( sizeof( _3DSTriObject_t ) * numTriObjects ); memcpy( pNO->pTriObjects, triObj, sizeof( triObj[0] ) * numTriObjects ); pNO->numTriObjects = numTriObjects; diff --git a/tools/quake3/q3data/models.c b/tools/quake3/q3data/models.c index 439ae020..83008af4 100644 --- a/tools/quake3/q3data/models.c +++ b/tools/quake3/q3data/models.c @@ -641,7 +641,7 @@ static void BuildBaseFrame( const char *filename, ObjectAnimationFrame_t *pOAF ) pOAF->surfaces[i]->numtriangles, g_data.surfData[i].baseTriangles ); - strcpy( g_data.surfData[i].header.name, pOAF->surfaces[i]->name ); + Q_strncpyz( g_data.surfData[i].header.name, pOAF->surfaces[i]->name, sizeof( g_data.surfData[i].header.name ) ); g_data.surfData[i].header.numTriangles = pOAF->surfaces[i]->numtriangles; g_data.surfData[i].header.numVerts = 0; @@ -662,7 +662,7 @@ static void BuildBaseFrame( const char *filename, ObjectAnimationFrame_t *pOAF ) strcpy( shaderName, pOAF->surfaces[i]->materialname ); */ - strcpy( g_data.surfData[i].shaders[g_data.surfData[i].header.numShaders].name, pOAF->surfaces[i]->materialname ); + Q_strncpyz( g_data.surfData[i].shaders[g_data.surfData[i].header.numShaders].name, pOAF->surfaces[i]->materialname, sizeof( g_data.surfData[i].shaders[g_data.surfData[i].header.numShaders].name ) ); g_data.surfData[i].header.numShaders++; } diff --git a/tools/quake3/q3data/video.c b/tools/quake3/q3data/video.c index 1605881a..93d3828e 100644 --- a/tools/quake3/q3data/video.c +++ b/tools/quake3/q3data/video.c @@ -911,7 +911,7 @@ void Cmd_Video( void ){ clock_t start, stop; GetToken( qfalse ); - strcpy( s_base, token ); + Q_strncpyz( s_base, token, sizeof( s_base ) ); if ( g_release ) { // sprintf (savename, "video/%s.cin", token); // ReleaseFile (savename); @@ -919,7 +919,7 @@ void Cmd_Video( void ){ } GetToken( qfalse ); - strcpy( s_output_base, token ); + Q_strncpyz( s_output_base, token, sizeof( s_output_base ) ); GetToken( qfalse ); digits = atoi( token ); diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index 0ac29021..a8989c5d 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -147,7 +147,7 @@ static void SetCloneModelNumbers( void ){ } /* add the model key */ - sprintf( modelValue, "*%d", models ); + snprintf( modelValue, sizeof( modelValue ), "*%d", models ); SetKeyValue( &entities[ i ], "model", modelValue ); /* increment model count */ @@ -194,7 +194,7 @@ static void SetCloneModelNumbers( void ){ models = atoi( &value2[ 1 ] ); /* add the model key */ - sprintf( modelValue, "*%d", models ); + snprintf( modelValue, sizeof( modelValue ), "*%d", models ); SetKeyValue( &entities[ i ], "model", modelValue ); /* nuke the brushes/patches for this entity (fixme: leak!) */ diff --git a/tools/quake3/q3map2/bspfile_ibsp.c b/tools/quake3/q3map2/bspfile_ibsp.c index 792f73fe..e8c1356c 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.c +++ b/tools/quake3/q3map2/bspfile_ibsp.c @@ -550,7 +550,7 @@ void WriteIBSPFile( const char *filename ){ /* add marker lump */ time( &t ); - sprintf( marker, "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); + snprintf( marker, sizeof( marker ), "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 ); /* add lumps */ diff --git a/tools/quake3/q3map2/bspfile_rbsp.c b/tools/quake3/q3map2/bspfile_rbsp.c index c6ebfe45..ed966faf 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.c +++ b/tools/quake3/q3map2/bspfile_rbsp.c @@ -305,7 +305,7 @@ void WriteRBSPFile( const char *filename ){ /* add marker lump */ time( &t ); - sprintf( marker, "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); + snprintf( marker, sizeof( marker ), "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 ); /* add lumps */ diff --git a/tools/quake3/q3map2/convert_ase.c b/tools/quake3/q3map2/convert_ase.c index 930452e2..01bea00e 100644 --- a/tools/quake3/q3map2/convert_ase.c +++ b/tools/quake3/q3map2/convert_ase.c @@ -56,7 +56,7 @@ static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSur } /* print object header for each dsurf */ - sprintf( name, "mat%dmodel%dsurf%d", ds->shaderNum, modelNum, surfaceNum ); + snprintf( name, sizeof( name ), "mat%dmodel%dsurf%d", ds->shaderNum, modelNum, surfaceNum ); fprintf( f, "*GEOMOBJECT\t{\r\n" ); fprintf( f, "\t*NODE_NAME\t\"%s\"\r\n", name ); fprintf( f, "\t*NODE_TM\t{\r\n" ); @@ -301,13 +301,13 @@ int ConvertBSPToASE( char *bspName ){ Sys_Printf( "--- Convert BSP to ASE ---\n" ); /* create the ase filename from the bsp name */ - strcpy( name, bspName ); + Q_strncpyz( name, bspName, sizeof( name ) ); StripExtension( name ); - strcat( name, ".ase" ); + strncat( name, ".ase", sizeof( name ) ); Sys_Printf( "writing %s\n", name ); - ExtractFileBase( bspName, base ); - strcat( base, ".bsp" ); + ExtractFileBase( bspName, base, sizeof( base ) ); + strncat( base, ".bsp", sizeof( base ) ); /* open it */ f = fopen( name, "wb" ); diff --git a/tools/quake3/q3map2/convert_map.c b/tools/quake3/q3map2/convert_map.c index 26748c86..e810e3b1 100644 --- a/tools/quake3/q3map2/convert_map.c +++ b/tools/quake3/q3map2/convert_map.c @@ -384,13 +384,13 @@ int ConvertBSPToMap( char *bspName ){ Sys_Printf( "--- Convert BSP to MAP ---\n" ); /* create the bsp filename from the bsp name */ - strcpy( name, bspName ); + Q_strncpyz( name, bspName, sizeof( name ) ); StripExtension( name ); - strcat( name, "_converted.map" ); + strncat( name, "_converted.map", sizeof( name ) ); Sys_Printf( "writing %s\n", name ); - ExtractFileBase( bspName, base ); - strcat( base, ".bsp" ); + ExtractFileBase( bspName, base, sizeof( base ) ); + strncat( base, ".bsp", sizeof( base ) ); /* open it */ f = fopen( name, "wb" ); diff --git a/tools/quake3/q3map2/exportents.c b/tools/quake3/q3map2/exportents.c index 89fcf22a..f739fb34 100644 --- a/tools/quake3/q3map2/exportents.c +++ b/tools/quake3/q3map2/exportents.c @@ -58,9 +58,9 @@ void ExportEntities( void ){ Sys_FPrintf( SYS_VRB, "--- ExportEntities ---\n" ); /* do some path mangling */ - strcpy( filename, source ); + Q_strncpyz( filename, source, sizeof( filename ) ); StripExtension( filename ); - strcat( filename, ".ent" ); + strncat( filename, ".ent", sizeof( filename ) ); /* sanity check */ if ( bspEntData == NULL || bspEntDataSize == 0 ) { @@ -96,7 +96,7 @@ int ExportEntitiesMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index 2af46a6f..7b066c23 100644 --- a/tools/quake3/q3map2/image.c +++ b/tools/quake3/q3map2/image.c @@ -310,7 +310,7 @@ image_t *ImageFind( const char *filename ){ } /* strip file extension off name */ - strcpy( name, filename ); + Q_strncpyz( name, filename, sizeof( name ) ); StripExtension( name ); /* search list */ @@ -349,7 +349,7 @@ image_t *ImageLoad( const char *filename ){ } /* strip file extension off name */ - strcpy( name, filename ); + Q_strncpyz( name, filename, sizeof( name ) ); StripExtension( name ); /* try to find existing image */ @@ -380,7 +380,7 @@ image_t *ImageLoad( const char *filename ){ /* attempt to load tga */ StripExtension( name ); - strcat( name, ".tga" ); + strncat( name, ".tga", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height ); @@ -389,7 +389,7 @@ image_t *ImageLoad( const char *filename ){ { /* attempt to load png */ StripExtension( name ); - strcat( name, ".png" ); + strncat( name, ".png", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height ); @@ -398,7 +398,7 @@ image_t *ImageLoad( const char *filename ){ { /* attempt to load jpg */ StripExtension( name ); - strcat( name, ".jpg" ); + strncat( name, ".jpg", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { if ( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL ) { @@ -409,7 +409,7 @@ image_t *ImageLoad( const char *filename ){ { /* attempt to load dds */ StripExtension( name ); - strcat( name, ".dds" ); + strncat( name, ".dds", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height ); @@ -422,7 +422,7 @@ image_t *ImageLoad( const char *filename ){ Sys_Printf( "pf = %d\n", pf ); if ( image->width > 0 ) { StripExtension( name ); - strcat( name, "_converted.tga" ); + strncat( name, "_converted.tga", sizeof( name ) ); WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width, image->height ); } } diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 79f16f08..1a764629 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -2255,10 +2255,10 @@ int LightMain( int argc, char **argv ){ } /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); - strcpy( mapSource, ExpandArg( argv[ i ] ) ); + Q_strncpyz( mapSource, ExpandArg( argv[ i ] ), sizeof( mapSource ) ); StripExtension( mapSource ); DefaultExtension( mapSource, ".map", sizeof( mapSource ) ); diff --git a/tools/quake3/q3map2/light_bounce.c b/tools/quake3/q3map2/light_bounce.c index bc6fb91e..1979562e 100644 --- a/tools/quake3/q3map2/light_bounce.c +++ b/tools/quake3/q3map2/light_bounce.c @@ -909,10 +909,10 @@ void RadCreateDiffuseLights( void ){ FILE *file; light_t *light; - strcpy( dumpName, source ); + Q_strncpyz( dumpName, source, sizeof( dumpName ) ); StripExtension( dumpName ); - sprintf( ext, "_bounce_%03d.map", iterations ); - strcat( dumpName, ext ); + snprintf( ext, sizeof( ext ), "_bounce_%03d.map", iterations ); + strncat( dumpName, ext, sizeof( dumpName ) ); file = fopen( dumpName, "wb" ); Sys_Printf( "Writing %s...\n", dumpName ); if ( file ) { diff --git a/tools/quake3/q3map2/light_trace.c b/tools/quake3/q3map2/light_trace.c index c81e26e9..fae1d6c3 100644 --- a/tools/quake3/q3map2/light_trace.c +++ b/tools/quake3/q3map2/light_trace.c @@ -1371,9 +1371,9 @@ void SetupTraceNodes( void ){ /* open the file */ - strcpy( filename, source ); + Q_strncpyz( filename, source, sizeof( filename ) ); StripExtension( filename ); - strcat( filename, ".lin" ); + strncat( filename, ".lin", sizeof( name ) ); Sys_Printf( "Opening light trace file %s...\n", filename ); file = fopen( filename, "w" ); if ( file == NULL ) { diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index 01642716..5f177202 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -122,7 +122,7 @@ void ExportLightmaps( void ){ Sys_FPrintf( SYS_VRB, "--- ExportLightmaps ---\n" ); /* do some path mangling */ - strcpy( dirname, source ); + Q_strncpyz( dirname, source, sizeof( dirname ) ); StripExtension( dirname ); /* sanity check */ @@ -159,7 +159,7 @@ int ExportLightmapsMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); @@ -194,7 +194,7 @@ int ImportLightmapsMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); @@ -206,7 +206,7 @@ int ImportLightmapsMain( int argc, char **argv ){ Sys_FPrintf( SYS_VRB, "--- ImportLightmaps ---\n" ); /* do some path mangling */ - strcpy( dirname, source ); + Q_strncpyz( dirname, source, sizeof( dirname ) ); StripExtension( dirname ); /* sanity check */ @@ -2333,7 +2333,7 @@ void StoreSurfaceLightmaps( void ){ Sys_Printf( "--- StoreSurfaceLightmaps ---\n" ); /* setup */ - strcpy( dirname, source ); + Q_strncpyz( dirname, source, sizeof( dirname ) ); StripExtension( dirname ); memset( rgbGenValues, 0, sizeof( rgbGenValues ) ); memset( alphaGenValues, 0, sizeof( alphaGenValues ) ); @@ -3046,7 +3046,7 @@ void StoreSurfaceLightmaps( void ){ /* setup */ - sprintf( styleStages, "\n\t// Q3Map2 custom lightstyle stage(s)\n" ); + snprintf( styleStages, sizeof( styleStages ), "\n\t// Q3Map2 custom lightstyle stage(s)\n" ); dv = &bspDrawVerts[ ds->firstVert ]; /* depthFunc equal? */ @@ -3071,7 +3071,7 @@ void StoreSurfaceLightmaps( void ){ /* lightmap name */ if ( lm->outLightmapNums[ lightmapNum ] == lm->outLightmapNums[ 0 ] ) { - strcpy( lightmapName, "$lightmap" ); + Q_strncpyz( lightmapName, "$lightmap", sizeof( lightmapName ) ); } else{ snprintf( lightmapName, sizeof( lightmapName ), "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); @@ -3079,7 +3079,7 @@ void StoreSurfaceLightmaps( void ){ /* get rgbgen string */ if ( rgbGenValues[ style ] == NULL ) { - sprintf( key, "_style%drgbgen", style ); + snprintf( key, sizeof( key ), "_style%drgbgen", style ); rgbGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key ); if ( rgbGenValues[ style ][ 0 ] == '\0' ) { rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37"; @@ -3095,7 +3095,7 @@ void StoreSurfaceLightmaps( void ){ /* get alphagen string */ if ( alphaGenValues[ style ] == NULL ) { - sprintf( key, "_style%dalphagen", style ); + snprintf( key, sizeof( key ), "_style%dalphagen", style ); alphaGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key ); } if ( alphaGenValues[ style ][ 0 ] != '\0' ) { diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index ccd344d3..6eda701a 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -132,7 +132,7 @@ int FixAAS( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); @@ -152,9 +152,9 @@ int FixAAS( int argc, char **argv ){ while ( *ext ) { /* mangle name */ - strcpy( aas, source ); + Q_strncpyz( aas, source, sizeof( aas ) ); StripExtension( aas ); - strcat( aas, *ext ); + strncat( aas, *ext, sizeof( aas ) ); Sys_Printf( "Trying %s\n", aas ); ext++; @@ -241,7 +241,7 @@ int AnalyzeBSP( int argc, char **argv ){ } /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); Sys_Printf( "Loading %s\n", source ); /* load the file */ @@ -365,7 +365,7 @@ int BSPInfo( int count, char **fileNames ){ Sys_Printf( "---------------------------------\n" ); /* mangle filename and get size */ - strcpy( source, fileNames[ i ] ); + Q_strncpyz( source, fileNames[ i ], sizeof( source ) ); ExtractFileExtension( source, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "map" ) ) { StripExtension( source ); @@ -427,7 +427,7 @@ int ScaleBSPMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); @@ -447,7 +447,7 @@ int ScaleBSPMain( int argc, char **argv ){ GetVectorForKey( &entities[ i ], "origin", vec ); if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) ) { VectorScale( vec, scale, vec ); - sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); + snprintf( str, sizeof( str ), "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); SetKeyValue( &entities[ i ], "origin", str ); } @@ -455,7 +455,7 @@ int ScaleBSPMain( int argc, char **argv ){ f = FloatForKey( &entities[ i ], "lip" ); if ( f ) { f *= scale; - sprintf( str, "%f", f ); + snprintf( str, sizeof( str ), "%f", f ); SetKeyValue( &entities[ i ], "lip", str ); } } @@ -495,7 +495,7 @@ int ScaleBSPMain( int argc, char **argv ){ VectorCopy( gridSize, vec ); } VectorScale( vec, scale, vec ); - sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); + snprintf( str, sizeof( str ), "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); SetKeyValue( &entities[ 0 ], "gridsize", str ); /* write the bsp */ @@ -555,7 +555,7 @@ int ConvertBSPMain( int argc, char **argv ){ } /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index fd8b1c74..98f6da52 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -759,7 +759,7 @@ brush_t *FinishBrush( void ){ VectorAdd( buildBrush->mins, buildBrush->maxs, origin ); VectorScale( origin, 0.5, origin ); - sprintf( string, "%i %i %i", (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] ); + snprintf( string, sizeof( string ), "%i %i %i", (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] ); SetKeyValue( &entities[ numEntities - 1 ], "origin", string ); VectorCopy( origin, entities[ numEntities - 1 ].origin ); @@ -1019,7 +1019,7 @@ static void ParseRawBrush( qboolean onlyLights ){ /* read shader name */ GetToken( qfalse ); - strcpy( name, token ); + Q_strncpyz( name, token, sizeof( name ) ); /* bp */ if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { @@ -1489,8 +1489,8 @@ void LoadEntityIndexMap( entity_t *e ){ im->w = w; im->h = h; im->numLayers = numLayers; - strcpy( im->name, indexMapFilename ); - strcpy( im->shader, shader ); + Q_strncpyz( im->name, indexMapFilename, sizeof( im->name ) ); + Q_strncpyz( im->shader, shader, sizeof( im->shader ) ); im->pixels = pixels; /* get height offsets */ @@ -1500,7 +1500,7 @@ void LoadEntityIndexMap( entity_t *e ){ } if ( value[ 0 ] != '\0' ) { /* value is a space-seperated set of numbers */ - strcpy( offset, value ); + Q_strncpyz( offset, value, sizeof( offset ) ); search = offset; /* get each value */ diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index 3f703d4d..f8e5624e 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -312,13 +312,13 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade /* shader renaming for sof2 */ if ( renameModelShaders ) { - strcpy( shaderName, picoShaderName ); + Q_strncpyz( shaderName, picoShaderName, sizeof( shaderName ) ); StripExtension( shaderName ); if ( spawnFlags & 1 ) { - strcat( shaderName, "_RMG_BSP" ); + strncat( shaderName, "_RMG_BSP", sizeof( shaderName ) ); } else{ - strcat( shaderName, "_BSP" ); + strncat( shaderName, "_BSP", sizeof( shaderName ) ); } si = ShaderInfoForShader( shaderName ); } @@ -675,7 +675,7 @@ void AddTriangleModels( entity_t *e ){ remap2 = remap; remap = safe_malloc( sizeof( *remap ) ); remap->next = remap2; - strcpy( remap->from, ep->value ); + Q_strncpyz( remap->from, ep->value, sizeof( remap->from ) ); /* split the string */ split = strchr( remap->from, ';' ); @@ -688,7 +688,7 @@ void AddTriangleModels( entity_t *e ){ /* store the split */ *split = '\0'; - strcpy( remap->to, ( split + 1 ) ); + Q_strncpyz( remap->to, ( split + 1 ), sizeof( remap->to ) ); /* note it */ //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to ); diff --git a/tools/quake3/q3map2/patch.c b/tools/quake3/q3map2/patch.c index ba2ea8ba..81749bf1 100644 --- a/tools/quake3/q3map2/patch.c +++ b/tools/quake3/q3map2/patch.c @@ -236,7 +236,7 @@ void ParsePatch( qboolean onlyLights ){ /* get texture */ GetToken( qtrue ); - strcpy( texture, token ); + Q_strncpyz( texture, token, sizeof( texture ) ); Parse1DMatrix( 5, info ); m.width = info[0]; diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 2dd75cfb..62955103 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -401,7 +401,7 @@ void InitPaths( int *argc, char **argv ){ for ( i = 0; i < *argc && numBasePaths == 0; i++ ) { /* extract the arg */ - strcpy( temp, argv[ i ] ); + Q_strncpyz( temp, argv[ i ], sizeof( temp ) ); CleanPath( temp ); len = strlen( temp ); Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game->magic, temp, i ); diff --git a/tools/quake3/q3map2/shaders.c b/tools/quake3/q3map2/shaders.c index 4d95a99a..8aa2be07 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -297,14 +297,14 @@ void BeginMapShaderFile( const char *mapFile ){ } /* copy map name */ - strcpy( base, mapFile ); + Q_strncpyz( base, mapFile, sizeof( base ) ); StripExtension( base ); /* extract map name */ len = strlen( base ) - 1; while ( len > 0 && base[ len ] != '/' && base[ len ] != '\\' ) len--; - strcpy( mapName, &base[ len + 1 ] ); + Q_strncpyz( mapName, &base[ len + 1 ], sizeof( mapName ) ); base[ len ] = '\0'; if ( len <= 0 ) { return; @@ -525,10 +525,10 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ { /* substitute 'find' with 'replace' */ loc = s - srcShaderText; - strcpy( shaderText, srcShaderText ); + Q_strncpyz( shaderText, srcShaderText, sizeof( shaderText ) ); shaderText[ loc ] = '\0'; - strcat( shaderText, replace ); - strcat( shaderText, &srcShaderText[ loc + strlen( find ) ] ); + strncat( shaderText, replace, sizeof( shaderText ) ); + strncat( shaderText, &srcShaderText[ loc + strlen( find ) ], sizeof( shaderText ) ); } /* make md5 hash of the shader text */ @@ -551,7 +551,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* clone the existing shader and rename */ memcpy( csi, si, sizeof( shaderInfo_t ) ); - strcpy( csi->shader, shader ); + Q_strncpyz( csi->shader, shader, sizeof( csi->shader ) ); csi->custom = qtrue; /* store new shader text */ @@ -818,7 +818,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ } /* strip off extension */ - strcpy( shader, shaderName ); + Q_strncpyz( shader, shaderName, sizeof( shader ) ); StripExtension( shader ); /* search for it */ @@ -839,7 +839,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ /* allocate a default shader */ si = AllocShaderInfo(); - strcpy( si->shader, shader ); + Q_strncpyz( si->shader, shader, sizeof( si->shader ) ); LoadShaderImages( si ); FinishShader( si ); @@ -875,15 +875,15 @@ qboolean GetTokenAppend( char *buffer, qboolean crossline ){ /* append? */ if ( oldScriptLine != scriptline ) { - strcat( buffer, "\n" ); + strncat( buffer, "\n", sizeof( buffer ) ); for ( i = 0; i < tabDepth; i++ ) - strcat( buffer, "\t" ); + strncat( buffer, "\t", sizeof( buffer ) ); } else{ - strcat( buffer, " " ); + strncat( buffer, " ", sizeof( buffer ) ); } oldScriptLine = scriptline; - strcat( buffer, token ); + strncat( buffer, token, sizeof( buffer ) ); /* post-tabstops */ if ( token[ 0 ] == '{' ) { @@ -941,7 +941,7 @@ static void ParseShaderFile( const char *filename ){ { /* copy shader text to the shaderinfo */ if ( si != NULL && shaderText[ 0 ] != '\0' ) { - strcat( shaderText, "\n" ); + strncat( shaderText, "\n", sizeof( shaderText ) ); si->shaderText = safe_malloc( strlen( shaderText ) + 1 ); strcpy( si->shaderText, shaderText ); //% if( VectorLength( si->vecs[ 0 ] ) ) @@ -958,7 +958,7 @@ static void ParseShaderFile( const char *filename ){ /* shader name is initial token */ si = AllocShaderInfo(); - strcpy( si->shader, token ); + Q_strncpyz( si->shader, token, sizeof( si->shader ) ); /* ignore ":q3map" suffix */ suffix = strstr( si->shader, ":q3map" ); @@ -1026,7 +1026,7 @@ static void ParseShaderFile( const char *filename ){ /* get an image */ GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) { - strcpy( si->lightImagePath, token ); + Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); /* debug code */ @@ -1316,13 +1316,13 @@ static void ParseShaderFile( const char *filename ){ /* subclass it */ if ( si2 != NULL ) { /* preserve name */ - strcpy( temp, si->shader ); + Q_strncpyz( temp, si->shader, sizeof( temp ) ); /* copy shader */ memcpy( si, si2, sizeof( *si ) ); /* restore name and set to unfinished */ - strcpy( si->shader, temp ); + Q_strncpyz( si->shader, temp, sizeof( si->shader ) ); si->shaderWidth = 0; si->shaderHeight = 0; si->finished = qfalse; @@ -1342,7 +1342,7 @@ static void ParseShaderFile( const char *filename ){ /* get parameters */ GetTokenAppend( shaderText, qfalse ); - strcpy( model->model, token ); + Q_strncpyz( model->model, token, sizeof( model->model ) ); GetTokenAppend( shaderText, qfalse ); model->density = atof( token ); @@ -1376,7 +1376,7 @@ static void ParseShaderFile( const char *filename ){ /* get parameters */ GetTokenAppend( shaderText, qfalse ); - strcpy( foliage->model, token ); + Q_strncpyz( foliage->model, token, sizeof( foliage->model ) ); GetTokenAppend( shaderText, qfalse ); foliage->scale = atof( token ); @@ -1928,7 +1928,7 @@ static void ParseCustomInfoParms( void ){ } custSurfaceParms[ numCustSurfaceParms ].name = safe_malloc( MAX_OS_PATH ); - strcpy( custSurfaceParms[ numCustSurfaceParms ].name, token ); + Q_strncpyz( custSurfaceParms[ numCustSurfaceParms ].name, token, MAX_OS_PATH ); GetToken( qfalse ); sscanf( token, "%x", &custSurfaceParms[ numCustSurfaceParms ].contentFlags ); numCustSurfaceParms++; @@ -1954,7 +1954,7 @@ static void ParseCustomInfoParms( void ){ } custSurfaceParms[ numCustSurfaceParms ].name = safe_malloc( MAX_OS_PATH ); - strcpy( custSurfaceParms[ numCustSurfaceParms ].name, token ); + Q_strncpyz( custSurfaceParms[ numCustSurfaceParms ].name, token, MAX_OS_PATH ); GetToken( qfalse ); sscanf( token, "%x", &custSurfaceParms[ numCustSurfaceParms ].surfaceFlags ); numCustSurfaceParms++; @@ -2019,7 +2019,7 @@ void LoadShaderInfo( void ){ /* new shader file */ if ( j == numShaderFiles ) { shaderFiles[ numShaderFiles ] = safe_malloc( MAX_OS_PATH ); - strcpy( shaderFiles[ numShaderFiles ], token ); + Q_strncpyz( shaderFiles[ numShaderFiles ], token, MAX_OS_PATH ); numShaderFiles++; } } diff --git a/tools/quake3/q3map2/surface_extra.c b/tools/quake3/q3map2/surface_extra.c index 81c195e4..16503e29 100644 --- a/tools/quake3/q3map2/surface_extra.c +++ b/tools/quake3/q3map2/surface_extra.c @@ -227,9 +227,9 @@ void WriteSurfaceExtraFile( const char *path ){ Sys_Printf( "--- WriteSurfaceExtraFile ---\n" ); /* open the file */ - strcpy( srfPath, path ); + Q_strncpyz( srfPath, path, sizeof( srfPath ) ); StripExtension( srfPath ); - strcat( srfPath, ".srf" ); + strncat( srfPath, ".srf", sizeof( srfPath ) ); Sys_Printf( "Writing %s\n", srfPath ); sf = fopen( srfPath, "w" ); if ( sf == NULL ) { @@ -334,9 +334,9 @@ void LoadSurfaceExtraFile( const char *path ){ } /* load the file */ - strcpy( srfPath, path ); + Q_strncpyz( srfPath, path, sizeof( srfPath ) ); StripExtension( srfPath ); - strcat( srfPath, ".srf" ); + strncat( srfPath, ".srf", sizeof( srfPath ) ); Sys_Printf( "Loading %s\n", srfPath ); size = LoadFile( srfPath, (void**) &buffer ); if ( size <= 0 ) { diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 2b540110..fffa97e8 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -78,7 +78,7 @@ int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){ Error( "MAX_MAP_SHADERS" ); } numBSPShaders++; - strcpy( bspShaders[ i ].shader, shader ); + Q_strncpyz( bspShaders[ i ].shader, shader, sizeof( bspShaders[ i ].shader ) ); bspShaders[ i ].surfaceFlags = si->surfaceFlags; bspShaders[ i ].contentFlags = si->contentFlags; @@ -262,7 +262,7 @@ void SetModelNumbers( void ){ models = 1; for ( i = 1 ; i < numEntities ; i++ ) { if ( entities[i].brushes || entities[i].patches ) { - sprintf( value, "*%i", models ); + snprintf( value, sizeof( value ), "*%i", models ); models++; SetKeyValue( &entities[i], "model", value ); } @@ -341,18 +341,18 @@ void SetLightStyles( void ){ if ( numStyles == MAX_SWITCHED_LIGHTS ) { Error( "MAX_SWITCHED_LIGHTS (%d) exceeded, reduce the number of lights with targetnames", MAX_SWITCHED_LIGHTS ); } - strcpy( lightTargets[ j ], t ); + Q_strncpyz( lightTargets[ j ], t, sizeof( lightTargets[ j ] ) ); lightStyles[ j ] = style; numStyles++; } /* set explicit style */ - sprintf( value, "%d", 32 + j ); + snprintf( value, sizeof( value ), "%d", 32 + j ); SetKeyValue( e, "style", value ); /* set old style */ if ( style != LS_NORMAL ) { - sprintf( value, "%d", style ); + snprintf( value, sizeof( value ), "%d", style ); SetKeyValue( e, "switch_style", value ); } } @@ -506,7 +506,7 @@ void EmitFogs( void ){ for ( i = 0; i < numMapFogs; i++ ) { /* set shader */ - strcpy( bspFogs[ i ].shader, mapFogs[ i ].si->shader ); + Q_strncpyz( bspFogs[ i ].shader, mapFogs[ i ].si->shader, sizeof( bspFogs[ i ].shader ) ); /* global fog doesn't have an associated brush */ if ( mapFogs[ i ].brush == NULL ) { diff --git a/tools/urt/tools/quake3/q3map2/bsp.c b/tools/urt/tools/quake3/q3map2/bsp.c index d684bdcb..9295f7f3 100644 --- a/tools/urt/tools/quake3/q3map2/bsp.c +++ b/tools/urt/tools/quake3/q3map2/bsp.c @@ -74,7 +74,7 @@ static void SetCloneModelNumbers( void ){ } /* add the model key */ - sprintf( modelValue, "*%d", models ); + snprintf( modelValue, sizeof( modelValue ), "*%d", models ); SetKeyValue( &entities[ i ], "model", modelValue ); /* increment model count */ @@ -121,7 +121,7 @@ static void SetCloneModelNumbers( void ){ models = atoi( &value2[ 1 ] ); /* add the model key */ - sprintf( modelValue, "*%d", models ); + snprintf( modelValue, sizeof( modelValue ), "*%d", models ); SetKeyValue( &entities[ i ], "model", modelValue ); /* nuke the brushes/patches for this entity (fixme: leak!) */ @@ -617,7 +617,7 @@ int BSPMain( int argc, char **argv ){ onlyents = qtrue; } else if ( !strcmp( argv[ i ], "-tempname" ) ) { - strcpy( tempSource, argv[ ++i ] ); + Q_strncpyz( tempSource, argv[ ++i ], sizeof( tempSource ) ); } else if ( !strcmp( argv[ i ], "-tmpout" ) ) { strcpy( outbase, "/tmp" ); diff --git a/tools/urt/tools/quake3/q3map2/bspfile_abstract.c b/tools/urt/tools/quake3/q3map2/bspfile_abstract.c index 221e79c0..6d1e62c8 100644 --- a/tools/urt/tools/quake3/q3map2/bspfile_abstract.c +++ b/tools/urt/tools/quake3/q3map2/bspfile_abstract.c @@ -608,26 +608,26 @@ void UnparseEntities( void ){ } /* add beginning brace */ - strcat( end, "{\n" ); + strncat( end, "{\n", sizeof( bspEntData ) + bspEntData - end ); end += 2; /* walk epair list */ for ( ep = entities[ i ].epairs; ep != NULL; ep = ep->next ) { /* copy and clean */ - strcpy( key, ep->key ); + Q_strncpyz( key, ep->key, sizeof( key ) ); StripTrailing( key ); - strcpy( value, ep->value ); + Q_strncpyz( value, ep->value, sizeof( value ) ); StripTrailing( value ); /* add to buffer */ snprintf( line, sizeof( line ), "\"%s\" \"%s\"\n", key, value ); - strcat( end, line ); + strncat( end, line, sizeof( bspEntData ) + bspEntData - end ); end += strlen( line ); } /* add trailing brace */ - strcat( end,"}\n" ); + strncat( end, "}\n", sizeof( bspEntData ) + bspEntData - end ); end += 2; /* check for overflow */ diff --git a/tools/urt/tools/quake3/q3map2/bspfile_ibsp.c b/tools/urt/tools/quake3/q3map2/bspfile_ibsp.c index 25a2225f..59a94bad 100644 --- a/tools/urt/tools/quake3/q3map2/bspfile_ibsp.c +++ b/tools/urt/tools/quake3/q3map2/bspfile_ibsp.c @@ -542,7 +542,7 @@ void WriteIBSPFile( const char *filename ){ /* add marker lump */ time( &t ); - sprintf( marker, "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); + snprintf( marker, sizeof( marker ), "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 ); /* add lumps */ diff --git a/tools/urt/tools/quake3/q3map2/bspfile_rbsp.c b/tools/urt/tools/quake3/q3map2/bspfile_rbsp.c index c6ebfe45..ed966faf 100644 --- a/tools/urt/tools/quake3/q3map2/bspfile_rbsp.c +++ b/tools/urt/tools/quake3/q3map2/bspfile_rbsp.c @@ -305,7 +305,7 @@ void WriteRBSPFile( const char *filename ){ /* add marker lump */ time( &t ); - sprintf( marker, "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); + snprintf( marker, sizeof( marker ), "I LOVE MY Q3MAP2 %s on %s)", Q3MAP_VERSION, asctime( localtime( &t ) ) ); AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 ); /* add lumps */ diff --git a/tools/urt/tools/quake3/q3map2/convert_ase.c b/tools/urt/tools/quake3/q3map2/convert_ase.c index 53cbe85c..01bea00e 100644 --- a/tools/urt/tools/quake3/q3map2/convert_ase.c +++ b/tools/urt/tools/quake3/q3map2/convert_ase.c @@ -56,7 +56,7 @@ static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSur } /* print object header for each dsurf */ - sprintf( name, "mat%dmodel%dsurf%d", ds->shaderNum, modelNum, surfaceNum ); + snprintf( name, sizeof( name ), "mat%dmodel%dsurf%d", ds->shaderNum, modelNum, surfaceNum ); fprintf( f, "*GEOMOBJECT\t{\r\n" ); fprintf( f, "\t*NODE_NAME\t\"%s\"\r\n", name ); fprintf( f, "\t*NODE_TM\t{\r\n" ); @@ -306,7 +306,7 @@ int ConvertBSPToASE( char *bspName ){ strncat( name, ".ase", sizeof( name ) ); Sys_Printf( "writing %s\n", name ); - ExtractFileBase( bspName, base ); + ExtractFileBase( bspName, base, sizeof( base ) ); strncat( base, ".bsp", sizeof( base ) ); /* open it */ diff --git a/tools/urt/tools/quake3/q3map2/convert_map.c b/tools/urt/tools/quake3/q3map2/convert_map.c index 26748c86..e810e3b1 100644 --- a/tools/urt/tools/quake3/q3map2/convert_map.c +++ b/tools/urt/tools/quake3/q3map2/convert_map.c @@ -384,13 +384,13 @@ int ConvertBSPToMap( char *bspName ){ Sys_Printf( "--- Convert BSP to MAP ---\n" ); /* create the bsp filename from the bsp name */ - strcpy( name, bspName ); + Q_strncpyz( name, bspName, sizeof( name ) ); StripExtension( name ); - strcat( name, "_converted.map" ); + strncat( name, "_converted.map", sizeof( name ) ); Sys_Printf( "writing %s\n", name ); - ExtractFileBase( bspName, base ); - strcat( base, ".bsp" ); + ExtractFileBase( bspName, base, sizeof( base ) ); + strncat( base, ".bsp", sizeof( base ) ); /* open it */ f = fopen( name, "wb" ); diff --git a/tools/urt/tools/quake3/q3map2/exportents.c b/tools/urt/tools/quake3/q3map2/exportents.c index 89fcf22a..f739fb34 100644 --- a/tools/urt/tools/quake3/q3map2/exportents.c +++ b/tools/urt/tools/quake3/q3map2/exportents.c @@ -58,9 +58,9 @@ void ExportEntities( void ){ Sys_FPrintf( SYS_VRB, "--- ExportEntities ---\n" ); /* do some path mangling */ - strcpy( filename, source ); + Q_strncpyz( filename, source, sizeof( filename ) ); StripExtension( filename ); - strcat( filename, ".ent" ); + strncat( filename, ".ent", sizeof( filename ) ); /* sanity check */ if ( bspEntData == NULL || bspEntDataSize == 0 ) { @@ -96,7 +96,7 @@ int ExportEntitiesMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); diff --git a/tools/urt/tools/quake3/q3map2/image.c b/tools/urt/tools/quake3/q3map2/image.c index 891bdc9a..9ccca23b 100644 --- a/tools/urt/tools/quake3/q3map2/image.c +++ b/tools/urt/tools/quake3/q3map2/image.c @@ -310,7 +310,7 @@ image_t *ImageFind( const char *filename ){ } /* strip file extension off name */ - strcpy( name, filename ); + Q_strncpyz( name, filename, sizeof( name ) ); StripExtension( name ); /* search list */ @@ -349,7 +349,7 @@ image_t *ImageLoad( const char *filename ){ } /* strip file extension off name */ - strcpy( name, filename ); + Q_strncpyz( name, filename, sizeof( name ) ); StripExtension( name ); /* try to find existing image */ @@ -380,7 +380,7 @@ image_t *ImageLoad( const char *filename ){ /* attempt to load tga */ StripExtension( name ); - strcat( name, ".tga" ); + strncat( name, ".tga", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height ); @@ -389,7 +389,7 @@ image_t *ImageLoad( const char *filename ){ { /* attempt to load png */ StripExtension( name ); - strcat( name, ".png" ); + strncat( name, ".png", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height ); @@ -398,7 +398,7 @@ image_t *ImageLoad( const char *filename ){ { /* attempt to load jpg */ StripExtension( name ); - strcat( name, ".jpg" ); + strncat( name, ".jpg", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { if ( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL ) { @@ -409,7 +409,7 @@ image_t *ImageLoad( const char *filename ){ { /* attempt to load dds */ StripExtension( name ); - strcat( name, ".dds" ); + strncat( name, ".dds", sizeof( name ) ); size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height ); @@ -422,7 +422,7 @@ image_t *ImageLoad( const char *filename ){ Sys_Printf( "pf = %d\n", pf ); if ( image->width > 0 ) { StripExtension( name ); - strcat( name, "_converted.tga" ); + strncat( name, "_converted.tga", sizeof( name ) ); WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width, image->height ); } } diff --git a/tools/urt/tools/quake3/q3map2/light.c b/tools/urt/tools/quake3/q3map2/light.c index 03bf40c0..e98c81f8 100644 --- a/tools/urt/tools/quake3/q3map2/light.c +++ b/tools/urt/tools/quake3/q3map2/light.c @@ -1675,7 +1675,7 @@ void SetupGrid( void ){ /* different? */ if ( !VectorCompare( gridSize, oldGridSize ) ) { - sprintf( temp, "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] ); + snprintf( temp, sizeof( temp ), "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] ); SetKeyValue( &entities[ 0 ], "gridsize", (const char*) temp ); Sys_FPrintf( SYS_VRB, "Storing adjusted grid size\n" ); } @@ -2482,10 +2482,10 @@ int LightMain( int argc, char **argv ){ } /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); - strcpy( mapSource, ExpandArg( argv[ i ] ) ); + Q_strncpyz( mapSource, ExpandArg( argv[ i ] ), sizeof( mapSource ) ); StripExtension( mapSource ); DefaultExtension( mapSource, ".map", sizeof( mapSource ) ); diff --git a/tools/urt/tools/quake3/q3map2/light_bounce.c b/tools/urt/tools/quake3/q3map2/light_bounce.c index 97ef4781..8ea2f6db 100644 --- a/tools/urt/tools/quake3/q3map2/light_bounce.c +++ b/tools/urt/tools/quake3/q3map2/light_bounce.c @@ -909,10 +909,10 @@ void RadCreateDiffuseLights( void ){ FILE *file; light_t *light; - strcpy( dumpName, source ); + Q_strncpyz( dumpName, source, sizeof( dumpName ) ); StripExtension( dumpName ); - sprintf( ext, "_bounce_%03d.map", iterations ); - strcat( dumpName, ext ); + snprintf( ext, sizeof( ext ), "_bounce_%03d.map", iterations ); + strncat( dumpName, ext, sizeof( dumpName ) ); file = fopen( dumpName, "wb" ); Sys_Printf( "Writing %s...\n", dumpName ); if ( file ) { diff --git a/tools/urt/tools/quake3/q3map2/light_trace.c b/tools/urt/tools/quake3/q3map2/light_trace.c index c81e26e9..013f00cf 100644 --- a/tools/urt/tools/quake3/q3map2/light_trace.c +++ b/tools/urt/tools/quake3/q3map2/light_trace.c @@ -1371,9 +1371,9 @@ void SetupTraceNodes( void ){ /* open the file */ - strcpy( filename, source ); + Q_strncpyz( filename, source, sizeof( filename ) ); StripExtension( filename ); - strcat( filename, ".lin" ); + strncat( filename, ".lin", sizeof( filename ) ); Sys_Printf( "Opening light trace file %s...\n", filename ); file = fopen( filename, "w" ); if ( file == NULL ) { diff --git a/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c index 8ee307e8..a716db4a 100644 --- a/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c @@ -157,7 +157,7 @@ int ExportLightmapsMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); @@ -2328,7 +2328,7 @@ void StoreSurfaceLightmaps( void ){ Sys_Printf( "--- StoreSurfaceLightmaps ---\n" ); /* setup */ - strcpy( dirname, source ); + Q_strncpyz( dirname, source, sizeof( dirname ) ); StripExtension( dirname ); memset( rgbGenValues, 0, sizeof( rgbGenValues ) ); memset( alphaGenValues, 0, sizeof( alphaGenValues ) ); @@ -2999,7 +2999,7 @@ void StoreSurfaceLightmaps( void ){ /* setup */ - sprintf( styleStages, "\n\t// Q3Map2 custom lightstyle stage(s)\n" ); + snprintf( styleStages, sizeof( styleStages ), "\n\t// Q3Map2 custom lightstyle stage(s)\n" ); dv = &bspDrawVerts[ ds->firstVert ]; /* depthFunc equal? */ @@ -3032,7 +3032,7 @@ void StoreSurfaceLightmaps( void ){ /* get rgbgen string */ if ( rgbGenValues[ style ] == NULL ) { - sprintf( key, "_style%drgbgen", style ); + snprintf( key, sizeof( key ), "_style%drgbgen", style ); rgbGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key ); if ( rgbGenValues[ style ][ 0 ] == '\0' ) { rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37"; @@ -3048,7 +3048,7 @@ void StoreSurfaceLightmaps( void ){ /* get alphagen string */ if ( alphaGenValues[ style ] == NULL ) { - sprintf( key, "_style%dalphagen", style ); + snprintf( key, sizeof( key ), "_style%dalphagen", style ); alphaGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key ); } if ( alphaGenValues[ style ][ 0 ] != '\0' ) { diff --git a/tools/urt/tools/quake3/q3map2/main.c b/tools/urt/tools/quake3/q3map2/main.c index 8ef5ded5..10ec308a 100644 --- a/tools/urt/tools/quake3/q3map2/main.c +++ b/tools/urt/tools/quake3/q3map2/main.c @@ -129,7 +129,7 @@ int AnalyzeBSP( int argc, char **argv ){ } /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); Sys_Printf( "Loading %s\n", source ); /* load the file */ @@ -253,7 +253,7 @@ int BSPInfo( int count, char **fileNames ){ Sys_Printf( "---------------------------------\n" ); /* mangle filename and get size */ - strcpy( source, fileNames[ i ] ); + Q_strncpyz( source, fileNames[ i ], sizeof( source ) ); ExtractFileExtension( source, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "map" ) ) { StripExtension( source ); @@ -315,7 +315,7 @@ int ScaleBSPMain( int argc, char **argv ){ } /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + Q_strncpyz( source, ExpandArg( argv[ argc - 1 ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); @@ -335,7 +335,7 @@ int ScaleBSPMain( int argc, char **argv ){ GetVectorForKey( &entities[ i ], "origin", vec ); if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) ) { VectorScale( vec, scale, vec ); - sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); + snprintf( str, sizeof( str ), "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); SetKeyValue( &entities[ i ], "origin", str ); } @@ -343,7 +343,7 @@ int ScaleBSPMain( int argc, char **argv ){ f = FloatForKey( &entities[ i ], "lip" ); if ( f ) { f *= scale; - sprintf( str, "%f", f ); + snprintf( str, sizeof( str ), "%f", f ); SetKeyValue( &entities[ i ], "lip", str ); } } @@ -383,7 +383,7 @@ int ScaleBSPMain( int argc, char **argv ){ VectorCopy( gridSize, vec ); } VectorScale( vec, scale, vec ); - sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); + snprintf( str, sizeof( str ), "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); SetKeyValue( &entities[ 0 ], "gridsize", str ); /* write the bsp */ @@ -443,7 +443,7 @@ int ConvertBSPMain( int argc, char **argv ){ } /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); StripExtension( source ); DefaultExtension( source, ".bsp", sizeof( source ) ); diff --git a/tools/urt/tools/quake3/q3map2/map.c b/tools/urt/tools/quake3/q3map2/map.c index 8e185466..e4c2c8a6 100644 --- a/tools/urt/tools/quake3/q3map2/map.c +++ b/tools/urt/tools/quake3/q3map2/map.c @@ -859,7 +859,7 @@ static void ParseRawBrush( qboolean onlyLights ){ /* read shader name */ GetToken( qfalse ); - strcpy( name, token ); + Q_strncpyz( name, token, sizeof( name ) ); /* bp */ if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { @@ -1329,8 +1329,8 @@ void LoadEntityIndexMap( entity_t *e ){ im->w = w; im->h = h; im->numLayers = numLayers; - strcpy( im->name, indexMapFilename ); - strcpy( im->shader, shader ); + Q_strncpyz( im->name, indexMapFilename, sizeof( im->name ) ); + Q_strncpyz( im->shader, shader, sizeof( im->shader ) ); im->pixels = pixels; /* get height offsets */ @@ -1340,7 +1340,7 @@ void LoadEntityIndexMap( entity_t *e ){ } if ( value[ 0 ] != '\0' ) { /* value is a space-seperated set of numbers */ - strcpy( offset, value ); + Q_strncpyz( offset, value, sizeof( offset ) ); search = offset; /* get each value */ diff --git a/tools/urt/tools/quake3/q3map2/model.c b/tools/urt/tools/quake3/q3map2/model.c index 38003d4b..1e6bf17f 100644 --- a/tools/urt/tools/quake3/q3map2/model.c +++ b/tools/urt/tools/quake3/q3map2/model.c @@ -331,13 +331,13 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade /* shader renaming for sof2 */ if ( renameModelShaders ) { - strcpy( shaderName, picoShaderName ); + Q_strncpyz( shaderName, picoShaderName, sizeof( shaderName ) ); StripExtension( shaderName ); if ( spawnFlags & 1 ) { - strcat( shaderName, "_RMG_BSP" ); + strncat( shaderName, "_RMG_BSP", sizeof( shaderName ) ); } else{ - strcat( shaderName, "_BSP" ); + strncat( shaderName, "_BSP", sizeof( shaderName ) ); } si = ShaderInfoForShader( shaderName ); } @@ -742,7 +742,7 @@ void AddTriangleModels( entity_t *e ){ remap2 = remap; remap = safe_malloc( sizeof( *remap ) ); remap->next = remap2; - strcpy( remap->from, ep->value ); + Q_strncpyz( remap->from, ep->value, sizeof( remap->from ) ); /* split the string */ split = strchr( remap->from, ';' ); @@ -755,7 +755,7 @@ void AddTriangleModels( entity_t *e ){ /* store the split */ *split = '\0'; - strcpy( remap->to, ( split + 1 ) ); + Q_strncpyz( remap->to, ( split + 1 ), sizeof( remap->to ) ); /* note it */ //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to ); diff --git a/tools/urt/tools/quake3/q3map2/patch.c b/tools/urt/tools/quake3/q3map2/patch.c index ba2ea8ba..81749bf1 100644 --- a/tools/urt/tools/quake3/q3map2/patch.c +++ b/tools/urt/tools/quake3/q3map2/patch.c @@ -236,7 +236,7 @@ void ParsePatch( qboolean onlyLights ){ /* get texture */ GetToken( qtrue ); - strcpy( texture, token ); + Q_strncpyz( texture, token, sizeof( texture ) ); Parse1DMatrix( 5, info ); m.width = info[0]; diff --git a/tools/urt/tools/quake3/q3map2/path_init.c b/tools/urt/tools/quake3/q3map2/path_init.c index 19c8c782..f98094c4 100644 --- a/tools/urt/tools/quake3/q3map2/path_init.c +++ b/tools/urt/tools/quake3/q3map2/path_init.c @@ -118,7 +118,7 @@ void LokiInitPaths( char *argv0 ){ } /* do some path divining */ - strcpy( temp, argv0 ); + Q_strncpyz( temp, argv0, sizeof( temp ) ); if ( strrchr( temp, '/' ) ) { argv0 = strrchr( argv0, '/' ) + 1; } @@ -146,17 +146,17 @@ void LokiInitPaths( char *argv0 ){ /* found home dir candidate */ if ( *path == '~' ) { - strcpy( temp, home ); + Q_strncpyz( temp, home, sizeof( temp ) ); path++; } /* concatenate */ if ( last > ( path + 1 ) ) { strncat( temp, path, ( last - path ) ); - strcat( temp, "/" ); + strncat( temp, "/", sizeof( temp ) ); } - strcat( temp, "./" ); - strcat( temp, argv0 ); + strncat( temp, "./", sizeof( temp ) ); + strncat( temp, argv0, sizeof( temp ) ); /* verify the path */ if ( access( temp, X_OK ) == 0 ) { @@ -399,7 +399,7 @@ void InitPaths( int *argc, char **argv ){ for ( i = 0; i < *argc && numBasePaths == 0; i++ ) { /* extract the arg */ - strcpy( temp, argv[ i ] ); + Q_strncpyz( temp, argv[ i ], sizeof( temp ) ); CleanPath( temp ); len = strlen( temp ); Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game->magic, temp, i ); diff --git a/tools/urt/tools/quake3/q3map2/shaders.c b/tools/urt/tools/quake3/q3map2/shaders.c index c19399e5..a9b02a5f 100644 --- a/tools/urt/tools/quake3/q3map2/shaders.c +++ b/tools/urt/tools/quake3/q3map2/shaders.c @@ -524,10 +524,10 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ { /* substitute 'find' with 'replace' */ loc = s - srcShaderText; - strcpy( shaderText, srcShaderText ); + Q_strncpyz( shaderText, srcShaderText, sizeof( shaderText ) ); shaderText[ loc ] = '\0'; - strcat( shaderText, replace ); - strcat( shaderText, &srcShaderText[ loc + strlen( find ) ] ); + strncat( shaderText, replace, sizeof( shaderText ) ); + strncat( shaderText, &srcShaderText[ loc + strlen( find ) ], sizeof( shaderText ) ); } /* make md5 hash of the shader text */ @@ -550,7 +550,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* clone the existing shader and rename */ memcpy( csi, si, sizeof( shaderInfo_t ) ); - strcpy( csi->shader, shader ); + Q_strncpyz( csi->shader, shader, sizeof( csi->shader ) ); csi->custom = qtrue; /* store new shader text */ @@ -822,7 +822,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ } /* strip off extension */ - strcpy( shader, shaderName ); + Q_strncpyz( shader, shaderName, sizeof( shader ) ); StripExtension( shader ); /* search for it */ @@ -843,7 +843,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ /* allocate a default shader */ si = AllocShaderInfo(); - strcpy( si->shader, shader ); + Q_strncpyz( si->shader, shader, sizeof( si->shader ) ); LoadShaderImages( si ); FinishShader( si ); @@ -861,7 +861,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ static int oldScriptLine = 0; static int tabDepth = 0; -qboolean GetTokenAppend( char *buffer, qboolean crossline ){ +qboolean GetTokenAppend( char *buffer, qboolean crossline, size_t length ){ qboolean r; int i; @@ -879,15 +879,15 @@ qboolean GetTokenAppend( char *buffer, qboolean crossline ){ /* append? */ if ( oldScriptLine != scriptline ) { - strcat( buffer, "\n" ); + strncat( buffer, "\n", length ); for ( i = 0; i < tabDepth; i++ ) - strcat( buffer, "\t" ); + strncat( buffer, "\t", length ); } else{ - strcat( buffer, " " ); + strncat( buffer, " ", length ); } oldScriptLine = scriptline; - strcat( buffer, token ); + strncat( buffer, token, length ); /* post-tabstops */ if ( token[ 0 ] == '{' ) { @@ -899,21 +899,21 @@ qboolean GetTokenAppend( char *buffer, qboolean crossline ){ } -void Parse1DMatrixAppend( char *buffer, int x, vec_t *m ){ +void Parse1DMatrixAppend( char *buffer, int x, vec_t *m, size_t length ){ int i; - if ( !GetTokenAppend( buffer, qtrue ) || strcmp( token, "(" ) ) { + if ( !GetTokenAppend( buffer, qtrue, length ) || strcmp( token, "(" ) ) { Error( "Parse1DMatrixAppend(): line %d: ( not found!", scriptline ); } for ( i = 0; i < x; i++ ) { - if ( !GetTokenAppend( buffer, qfalse ) ) { + if ( !GetTokenAppend( buffer, qfalse, length ) ) { Error( "Parse1DMatrixAppend(): line %d: Number not found!", scriptline ); } m[ i ] = atof( token ); } - if ( !GetTokenAppend( buffer, qtrue ) || strcmp( token, ")" ) ) { + if ( !GetTokenAppend( buffer, qtrue, length ) || strcmp( token, ")" ) ) { Error( "Parse1DMatrixAppend(): line %d: ) not found!", scriptline ); } } @@ -945,7 +945,7 @@ static void ParseShaderFile( const char *filename ){ { /* copy shader text to the shaderinfo */ if ( si != NULL && shaderText[ 0 ] != '\0' ) { - strcat( shaderText, "\n" ); + strncat( shaderText, "\n", sizeof( shaderText ) ); si->shaderText = safe_malloc( strlen( shaderText ) + 1 ); strcpy( si->shaderText, shaderText ); //% if( VectorLength( si->vecs[ 0 ] ) ) @@ -962,7 +962,7 @@ static void ParseShaderFile( const char *filename ){ /* shader name is initial token */ si = AllocShaderInfo(); - strcpy( si->shader, token ); + Q_strncpyz( si->shader, token, sizeof( si->shader ) ); /* ignore ":q3map" suffix */ suffix = strstr( si->shader, ":q3map" ); @@ -971,7 +971,7 @@ static void ParseShaderFile( const char *filename ){ } /* handle { } section */ - if ( !GetTokenAppend( shaderText, qtrue ) ) { + if ( !GetTokenAppend( shaderText, qtrue, sizeof( shaderText ) ) ) { break; } if ( strcmp( token, "{" ) ) { @@ -988,7 +988,7 @@ static void ParseShaderFile( const char *filename ){ while ( 1 ) { /* get the next token */ - if ( !GetTokenAppend( shaderText, qtrue ) ) { + if ( !GetTokenAppend( shaderText, qtrue, sizeof( shaderText ) ) ) { break; } if ( !strcmp( token, "}" ) ) { @@ -1005,7 +1005,7 @@ static void ParseShaderFile( const char *filename ){ si->hasPasses = qtrue; while ( 1 ) { - if ( !GetTokenAppend( shaderText, qtrue ) ) { + if ( !GetTokenAppend( shaderText, qtrue, sizeof( shaderText ) ) ) { break; } if ( !strcmp( token, "}" ) ) { @@ -1024,11 +1024,11 @@ static void ParseShaderFile( const char *filename ){ !Q_stricmp( token, "mapNoComp" ) ) { /* skip one token for animated stages */ if ( !Q_stricmp( token, "animMap" ) || !Q_stricmp( token, "clampAnimMap" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); } /* get an image */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) { Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); @@ -1048,7 +1048,7 @@ static void ParseShaderFile( const char *filename ){ /* match surfaceparm */ else if ( !Q_stricmp( token, "surfaceparm" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( ApplySurfaceParm( token, &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) == qfalse ) { Sys_Printf( "WARNING: Unknown surfaceparm: \"%s\"\n", token ); } @@ -1071,13 +1071,13 @@ static void ParseShaderFile( const char *filename ){ /* tesssize is used to force liquid surfaces to subdivide */ else if ( !Q_stricmp( token, "tessSize" ) || !Q_stricmp( token, "q3map_tessSize" ) /* sof2 */ ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->subdivisions = atof( token ); } /* cull none will set twoSided (ydnar: added disable too) */ else if ( !Q_stricmp( token, "cull" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( !Q_stricmp( token, "none" ) || !Q_stricmp( token, "disable" ) || !Q_stricmp( token, "twosided" ) ) { si->twoSided = qtrue; } @@ -1087,7 +1087,7 @@ static void ParseShaderFile( const char *filename ){ we catch this so autosprited surfaces become point lights instead of area lights */ else if ( !Q_stricmp( token, "deformVertexes" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); /* deformVertexes autosprite(2) */ if ( !Q_strncasecmp( token, "autosprite", 10 ) ) { @@ -1107,16 +1107,16 @@ static void ParseShaderFile( const char *filename ){ /* get move amount */ - GetTokenAppend( shaderText, qfalse ); amt[ 0 ] = atof( token ); - GetTokenAppend( shaderText, qfalse ); amt[ 1 ] = atof( token ); - GetTokenAppend( shaderText, qfalse ); amt[ 2 ] = atof( token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); amt[ 0 ] = atof( token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); amt[ 1 ] = atof( token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); amt[ 2 ] = atof( token ); /* skip func */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); /* get base and amplitude */ - GetTokenAppend( shaderText, qfalse ); base = atof( token ); - GetTokenAppend( shaderText, qfalse ); amp = atof( token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); base = atof( token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); amp = atof( token ); /* calculate */ VectorScale( amt, base, mins ); @@ -1128,24 +1128,24 @@ static void ParseShaderFile( const char *filename ){ /* light (old-style flare specification) */ else if ( !Q_stricmp( token, "light" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->flareShader = game->flareShader; } /* ydnar: damageShader (sof2 mods) */ else if ( !Q_stricmp( token, "damageShader" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] != '\0' ) { si->damageShader = safe_malloc( strlen( token ) + 1 ); Q_strncpyz( si->damageShader, token, sizeof( si->damageShader ) ); } - GetTokenAppend( shaderText, qfalse ); /* don't do anything with health */ + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); /* don't do anything with health */ } /* ydnar: enemy territory implicit shaders */ else if ( !Q_stricmp( token, "implicitMap" ) ) { si->implicitMap = IM_OPAQUE; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } @@ -1156,7 +1156,7 @@ static void ParseShaderFile( const char *filename ){ else if ( !Q_stricmp( token, "implicitMask" ) ) { si->implicitMap = IM_MASKED; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } @@ -1167,7 +1167,7 @@ static void ParseShaderFile( const char *filename ){ else if ( !Q_stricmp( token, "implicitBlend" ) ) { si->implicitMap = IM_MASKED; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } @@ -1183,21 +1183,21 @@ static void ParseShaderFile( const char *filename ){ /* qer_editorimage */ else if ( !Q_stricmp( token, "qer_editorImage" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); Q_strncpyz( si->editorImagePath, token, sizeof( si->editorImagePath ) ); DefaultExtension( si->editorImagePath, ".tga", sizeof( si->editorImagePath ) ); } /* ydnar: q3map_normalimage (bumpmapping normal map) */ else if ( !Q_stricmp( token, "q3map_normalImage" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); Q_strncpyz( si->normalImagePath, token, sizeof( si->normalImagePath ) ); DefaultExtension( si->normalImagePath, ".tga", sizeof( si->normalImagePath ) ); } /* q3map_lightimage */ else if ( !Q_stricmp( token, "q3map_lightImage" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); } @@ -1205,7 +1205,7 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: skyparms */ else if ( !Q_stricmp( token, "skyParms" ) ) { /* get image base */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); /* ignore bogus paths */ if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) { @@ -1218,8 +1218,8 @@ static void ParseShaderFile( const char *filename ){ } /* skip rest of line */ - GetTokenAppend( shaderText, qfalse ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); } /* ----------------------------------------------------------------- @@ -1250,26 +1250,26 @@ static void ParseShaderFile( const char *filename ){ sun->style = si->lightStyle; /* get color */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); sun->color[ 0 ] = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); sun->color[ 1 ] = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); sun->color[ 2 ] = atof( token ); /* normalize it */ VectorNormalize( sun->color, sun->color ); /* scale color by brightness */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); sun->photons = atof( token ); /* get sun angle/elevation */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); a = atof( token ); a = a / 180.0f * Q_PI; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); b = atof( token ); b = b / 180.0f * Q_PI; @@ -1282,11 +1282,11 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: get sun angular deviance/samples */ if ( ext && TokenAvailable() ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); sun->deviance = atof( token ); sun->deviance = sun->deviance / 180.0f * Q_PI; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); sun->numSamples = atoi( token ); } @@ -1310,7 +1310,7 @@ static void ParseShaderFile( const char *filename ){ /* get shader */ - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); //% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, token ); oldWarnImage = warnImage; warnImage = qfalse; @@ -1320,13 +1320,13 @@ static void ParseShaderFile( const char *filename ){ /* subclass it */ if ( si2 != NULL ) { /* preserve name */ - strcpy( temp, si->shader ); + Q_strncpyz( temp, si->shader, sizeof( temp ) ); /* copy shader */ memcpy( si, si2, sizeof( *si ) ); /* restore name and set to unfinished */ - strcpy( si->shader, temp ); + Q_strncpyz( si->shader, temp, sizeof( si->shader ) ); si->shaderWidth = 0; si->shaderHeight = 0; si->finished = qfalse; @@ -1345,25 +1345,25 @@ static void ParseShaderFile( const char *filename ){ si->surfaceModel = model; /* get parameters */ - GetTokenAppend( shaderText, qfalse ); - strcpy( model->model, token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); + Q_strncpyz( model->model, token, sizeof( model->model ) ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->density = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->odds = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->minScale = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->maxScale = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->minAngle = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->maxAngle = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); model->oriented = ( token[ 0 ] == '1' ? qtrue : qfalse ); } @@ -1379,30 +1379,30 @@ static void ParseShaderFile( const char *filename ){ si->foliage = foliage; /* get parameters */ - GetTokenAppend( shaderText, qfalse ); - strcpy( foliage->model, token ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); + Q_strncpyz( foliage->model, token, sizeof( foliage->model ) ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); foliage->scale = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); foliage->density = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); foliage->odds = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); foliage->inverseAlpha = atoi( token ); } /* ydnar: q3map_bounce (fraction of light to re-emit during radiosity passes) */ else if ( !Q_stricmp( token, "q3map_bounce" ) || !Q_stricmp( token, "q3map_bounceScale" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->bounceScale = atof( token ); } /* ydnar/splashdamage: q3map_skyLight */ else if ( !Q_stricmp( token, "q3map_skyLight" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->skyLightValue = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->skyLightIterations = atoi( token ); /* clamp */ @@ -1416,13 +1416,13 @@ static void ParseShaderFile( const char *filename ){ /* q3map_surfacelight */ else if ( !Q_stricmp( token, "q3map_surfacelight" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->value = atof( token ); } /* q3map_lightStyle (sof2/jk2 lightstyle) */ else if ( !Q_stricmp( token, "q3map_lightStyle" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); val = atoi( token ); if ( val < 0 ) { val = 0; @@ -1436,52 +1436,52 @@ static void ParseShaderFile( const char *filename ){ /* wolf: q3map_lightRGB */ else if ( !Q_stricmp( token, "q3map_lightRGB" ) ) { VectorClear( si->color ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->color[ 0 ] = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->color[ 1 ] = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->color[ 2 ] = atof( token ); ColorNormalize( si->color, si->color ); } /* q3map_lightSubdivide */ else if ( !Q_stricmp( token, "q3map_lightSubdivide" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lightSubdivide = atoi( token ); } /* q3map_backsplash */ else if ( !Q_stricmp( token, "q3map_backsplash" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->backsplashFraction = atof( token ) * 0.01f; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->backsplashDistance = atof( token ); } /* q3map_lightmapSampleSize */ else if ( !Q_stricmp( token, "q3map_lightmapSampleSize" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lightmapSampleSize = atoi( token ); } /* q3map_lightmapSampleSffset */ else if ( !Q_stricmp( token, "q3map_lightmapSampleOffset" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lightmapSampleOffset = atof( token ); } /* ydnar: q3map_lightmapFilterRadius */ else if ( !Q_stricmp( token, "q3map_lightmapFilterRadius" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lmFilterRadius = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lightFilterRadius = atof( token ); } /* ydnar: q3map_lightmapAxis [xyz] */ else if ( !Q_stricmp( token, "q3map_lightmapAxis" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( !Q_stricmp( token, "x" ) ) { VectorSet( si->lightmapAxis, 1, 0, 0 ); } @@ -1500,9 +1500,9 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: q3map_lightmapSize (for autogenerated shaders + external tga lightmaps) */ else if ( !Q_stricmp( token, "q3map_lightmapSize" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lmCustomWidth = atoi( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lmCustomHeight = atoi( token ); /* must be a power of 2 */ @@ -1517,7 +1517,7 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: q3map_lightmapBrightness N (for autogenerated shaders + external tga lightmaps) */ else if ( !Q_stricmp( token, "q3map_lightmapBrightness" ) || !Q_stricmp( token, "q3map_lightmapGamma" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->lmBrightness = atof( token ); if ( si->lmBrightness < 0 ) { si->lmBrightness = 1.0; @@ -1526,7 +1526,7 @@ static void ParseShaderFile( const char *filename ){ /* q3map_vertexScale (scale vertex lighting by this fraction) */ else if ( !Q_stricmp( token, "q3map_vertexScale" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->vertexScale = atof( token ); } @@ -1537,7 +1537,7 @@ static void ParseShaderFile( const char *filename ){ /* q3map_flare[Shader] */ else if ( !Q_stricmp( token, "q3map_flare" ) || !Q_stricmp( token, "q3map_flareShader" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] != '\0' ) { si->flareShader = safe_malloc( strlen( token ) + 1 ); strcpy( si->flareShader, token ); @@ -1546,7 +1546,7 @@ static void ParseShaderFile( const char *filename ){ /* q3map_backShader */ else if ( !Q_stricmp( token, "q3map_backShader" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] != '\0' ) { si->backShader = safe_malloc( strlen( token ) + 1 ); strcpy( si->backShader, token ); @@ -1555,7 +1555,7 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: q3map_cloneShader */ else if ( !Q_stricmp( token, "q3map_cloneShader" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] != '\0' ) { si->cloneShader = safe_malloc( strlen( token ) + 1 ); strcpy( si->cloneShader, token ); @@ -1564,7 +1564,7 @@ static void ParseShaderFile( const char *filename ){ /* q3map_remapShader */ else if ( !Q_stricmp( token, "q3map_remapShader" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] != '\0' ) { si->remapShader = safe_malloc( strlen( token ) + 1 ); strcpy( si->remapShader, token ); @@ -1573,17 +1573,17 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: q3map_offset */ else if ( !Q_stricmp( token, "q3map_offset" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->offset = atof( token ); } /* ydnar: q3map_textureSize (substitute for q3map_lightimage derivation for terrain) */ else if ( !Q_stricmp( token, "q3map_fur" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->furNumLayers = atoi( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->furOffset = atof( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->furFade = atof( token ); } @@ -1608,33 +1608,33 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: gs mods: q3map_shadeAngle */ else if ( !Q_stricmp( token, "q3map_shadeAngle" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->shadeAngleDegrees = atof( token ); } /* ydnar: q3map_textureSize (substitute for q3map_lightimage derivation for terrain) */ else if ( !Q_stricmp( token, "q3map_textureSize" ) ) { - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->shaderWidth = atoi( token ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); si->shaderHeight = atoi( token ); } /* ydnar: gs mods: q3map_tcGen