From a44b3bdfe1c0a526a703f3ba70fe20624ea501ee Mon Sep 17 00:00:00 2001 From: Pan7 Date: Tue, 16 Aug 2016 00:50:54 +0200 Subject: [PATCH] cleanup: strcpy to strncpy, strcat to strncat... --- contrib/bkgrnd2d/dialog.cpp | 11 +- contrib/bobtoolz/DBobView.cpp | 4 +- contrib/bobtoolz/DBrush.cpp | 8 +- contrib/bobtoolz/DEntity.cpp | 2 +- contrib/bobtoolz/DPatch.cpp | 4 +- contrib/bobtoolz/DShape.cpp | 8 +- contrib/bobtoolz/DTrainDrawer.cpp | 12 +- contrib/bobtoolz/DTreePlanter.cpp | 26 +- contrib/bobtoolz/DTreePlanter.h | 2 +- contrib/bobtoolz/bobToolz-GTK.cpp | 8 +- contrib/bobtoolz/dialogs/dialogs-gtk.cpp | 20 +- contrib/bobtoolz/funchandlers-GTK.cpp | 14 +- contrib/bobtoolz/misc.cpp | 24 +- contrib/bobtoolz/misc.h | 2 +- contrib/bobtoolz/shapes.cpp | 2 +- contrib/camera/dialogs.cpp | 18 +- contrib/camera/funchandlers.cpp | 20 +- contrib/camera/misc.cpp | 8 +- contrib/gtkgensurf/bitmap.cpp | 2 +- contrib/gtkgensurf/dec.cpp | 12 +- contrib/gtkgensurf/face.cpp | 6 +- contrib/gtkgensurf/gendlgs.cpp | 64 ++-- contrib/gtkgensurf/genmap.cpp | 90 ++--- contrib/gtkgensurf/gensurf.cpp | 36 +- contrib/gtkgensurf/triangle.c | 118 +++---- contrib/gtkgensurf/view.cpp | 6 +- contrib/hydratoolz/plugin.cpp | 10 +- contrib/prtview/ConfigDialog.cpp | 12 +- contrib/prtview/LoadPortalFileDialog.cpp | 4 +- contrib/prtview/prtview.cpp | 30 +- include/qerplugin.h | 6 + libs/cmdlib.h | 24 +- libs/cmdlib/cmdlib.cpp | 54 ++- libs/l_net/l_net.c | 2 +- libs/picomodel/picointernal.c | 6 +- libs/picomodel/picointernal.h | 8 +- libs/picomodel/picomodel.c | 9 +- libs/picomodel/pm_3ds.c | 13 +- libs/picomodel/pm_ase.c | 11 +- libs/picomodel/pm_fm.c | 4 +- libs/picomodel/pm_lwo.c | 4 +- libs/picomodel/pm_md2.c | 9 +- libs/picomodel/pm_md3.c | 2 +- libs/picomodel/pm_mdc.c | 2 +- libs/picomodel/pm_obj.c | 2 +- libs/splines/math_vector.cpp | 2 +- libs/splines/q_parse.cpp | 4 +- libs/splines/q_shared.cpp | 10 +- libs/splines/q_shared.h | 2 +- libs/splines/splines.cpp | 5 +- libs/splines/util_str.cpp | 8 +- libs/str.h | 9 + plugins/eclassfgd/plugin.cpp | 166 ++++----- plugins/imagem8/m8.cpp | 8 +- plugins/map/parse.cpp | 10 +- plugins/mapxml/xmlparse.cpp | 2 +- plugins/mapxml/xmlwrite.cpp | 44 +-- plugins/model/plugin.cpp | 16 +- plugins/model/remap.cpp | 2 +- plugins/shaders/shaders.cpp | 12 +- plugins/surface/surfacedialog.cpp | 13 +- plugins/surface_idtech2/surfacedialog.cpp | 12 +- plugins/surface_idtech2/surfaceflags.cpp | 13 +- plugins/vfspak/vfs.cpp | 58 ++-- plugins/vfspk3/vfs.cpp | 74 ++-- plugins/vfsqlpk3/vfs.cpp | 54 +-- plugins/vfswad/vfs.cpp | 66 ++-- plugins/vfswad/vfs.h | 2 +- radiant/brush.cpp | 16 +- radiant/dialog.cpp | 6 +- radiant/drag.cpp | 4 +- radiant/eclass.cpp | 16 +- radiant/eclass_def.cpp | 16 +- radiant/error.cpp | 26 +- radiant/file.cpp | 2 +- radiant/groupdialog.cpp | 18 +- radiant/gtkdlgs.cpp | 12 +- radiant/gtkmisc.cpp | 12 +- radiant/main.cpp | 107 +++--- radiant/mainframe.cpp | 66 ++-- radiant/map.cpp | 14 +- radiant/missing.cpp | 6 +- radiant/pluginentities.cpp | 6 +- radiant/pluginmanager.cpp | 14 +- radiant/pmesh.cpp | 12 +- radiant/points.cpp | 8 +- radiant/preferences.cpp | 46 +-- radiant/profile.cpp | 20 +- radiant/qe3.cpp | 45 +-- radiant/qe3.h | 4 +- radiant/select.cpp | 2 +- radiant/selectedface.cpp | 2 +- radiant/surfacedialog.cpp | 18 +- radiant/targetname.cpp | 2 +- radiant/texwindow.cpp | 24 +- radiant/watchbsp.cpp | 6 +- radiant/xywindow.cpp | 12 +- radiant/z.cpp | 2 +- tools/quake2/common/cmdlib.c | 14 +- tools/quake2/common/cmdlib.h | 4 +- tools/quake2/common/inout.c | 4 +- tools/quake2/common/qfiles.h | 2 +- tools/quake2/common/threads.c | 4 +- tools/quake2/extra/bsp/qrad3/qrad.h | 2 +- tools/quake2/extra/common/cmdlib.c | 6 +- tools/quake2/extra/common/threads.c | 2 +- tools/quake2/extra/qe4/mru.c | 2 +- tools/quake2/extra/qe4/mru.h | 2 +- tools/quake2/q2map/q2map.h | 2 +- tools/quake2/q2map/qbsp.h | 2 +- tools/quake2/q2map/qrad.h | 4 +- tools/quake2/q2map/qvis.h | 2 +- tools/quake2/qdata/qdata.h | 2 +- tools/quake2/qdata_heretic2/common/cmdlib.c | 8 +- tools/quake2/qdata_heretic2/common/inout.c | 4 +- tools/quake2/qdata_heretic2/common/threads.c | 4 +- tools/quake3/common/aselib.c | 32 +- tools/quake3/common/bspfile.c | 12 +- tools/quake3/common/cmdlib.c | 62 ++-- tools/quake3/common/cmdlib.h | 14 +- tools/quake3/common/imagelib.c | 6 +- tools/quake3/common/inout.c | 32 +- tools/quake3/common/mutex.c | 2 +- tools/quake3/common/scriplib.c | 4 +- tools/quake3/common/threads.c | 2 +- tools/quake3/common/trilib.c | 4 +- tools/quake3/common/vfs.c | 22 +- tools/quake3/q3data/3dslib.c | 42 +-- tools/quake3/q3data/md3lib.c | 2 +- tools/quake3/q3data/models.c | 4 +- tools/quake3/q3data/p3dlib.c | 2 +- tools/quake3/q3data/q3data.c | 6 +- tools/quake3/q3data/video.c | 8 +- tools/quake3/q3map2/bsp.c | 26 +- tools/quake3/q3map2/bsp_info.c | 4 +- tools/quake3/q3map2/bsp_scale.c | 4 +- tools/quake3/q3map2/bspfile_abstract.c | 14 +- tools/quake3/q3map2/bspfile_ibsp.c | 2 +- tools/quake3/q3map2/bspfile_rbsp.c | 2 +- tools/quake3/q3map2/convert_ase.c | 14 +- tools/quake3/q3map2/convert_bsp.c | 4 +- tools/quake3/q3map2/convert_map.c | 8 +- tools/quake3/q3map2/exportents.c | 8 +- tools/quake3/q3map2/fixaas.c | 2 +- tools/quake3/q3map2/image.c | 14 +- tools/quake3/q3map2/leakfile.c | 2 +- tools/quake3/q3map2/light.c | 12 +- tools/quake3/q3map2/light_bounce.c | 6 +- tools/quake3/q3map2/light_trace.c | 4 +- tools/quake3/q3map2/lightmaps_ydnar.c | 50 +-- tools/quake3/q3map2/main.c | 10 +- tools/quake3/q3map2/map.c | 18 +- tools/quake3/q3map2/model.c | 12 +- tools/quake3/q3map2/patch.c | 4 +- tools/quake3/q3map2/path_init.c | 8 +- tools/quake3/q3map2/prtfile.c | 2 +- tools/quake3/q3map2/q3map2.h | 12 +- tools/quake3/q3map2/shaders.c | 104 +++--- tools/quake3/q3map2/surface.c | 16 +- tools/quake3/q3map2/surface_extra.c | 8 +- tools/quake3/q3map2/vis.c | 8 +- tools/quake3/q3map2/writebsp.c | 18 +- tools/urt/tools/quake3/q3map2/bsp.c | 24 +- .../tools/quake3/q3map2/bspfile_abstract.c | 14 +- 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 | 14 +- tools/urt/tools/quake3/q3map2/convert_map.c | 8 +- tools/urt/tools/quake3/q3map2/exportents.c | 8 +- tools/urt/tools/quake3/q3map2/image.c | 14 +- tools/urt/tools/quake3/q3map2/leakfile.c | 2 +- tools/urt/tools/quake3/q3map2/light.c | 14 +- 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 | 50 +-- tools/urt/tools/quake3/q3map2/main.c | 28 +- tools/urt/tools/quake3/q3map2/map.c | 18 +- tools/urt/tools/quake3/q3map2/model.c | 12 +- tools/urt/tools/quake3/q3map2/patch.c | 4 +- tools/urt/tools/quake3/q3map2/path_init.c | 18 +- tools/urt/tools/quake3/q3map2/prtfile.c | 2 +- tools/urt/tools/quake3/q3map2/q3map2.h | 8 +- tools/urt/tools/quake3/q3map2/shaders.c | 316 +++++++++--------- tools/urt/tools/quake3/q3map2/surface.c | 16 +- tools/urt/tools/quake3/q3map2/surface_extra.c | 8 +- tools/urt/tools/quake3/q3map2/vis.c | 8 +- tools/urt/tools/quake3/q3map2/writebsp.c | 18 +- 187 files changed, 1668 insertions(+), 1547 deletions(-) diff --git a/contrib/bkgrnd2d/dialog.cpp b/contrib/bkgrnd2d/dialog.cpp index ae6eef27..c6e31569 100644 --- a/contrib/bkgrnd2d/dialog.cpp +++ b/contrib/bkgrnd2d/dialog.cpp @@ -36,8 +36,7 @@ // spaces to make label nice and big #define NO_FILE_MSG " (no file loaded) " -#ifdef _WIN32 -// TTimo: THIS IS UGLY +#if defined(_MSC_VER) && _MSC_VER<1900 && !(defined snprintf) #define snprintf _snprintf #endif @@ -124,17 +123,17 @@ void CBackgroundDialogPage::Browse(){ return; } - strcpy( browsedir,ct ); + Q_strncpyz( browsedir, ct, sizeof( browsedir ) ); // make sure we have a trailing / if ( browsedir[strlen( browsedir ) - 1] != '/' ) { - strcat( browsedir,"/" ); + strncat( browsedir, "/", sizeof( browsedir ) ); } //if we dont have a file yet, don't try to use it for default dir if ( m_bValidFile ) { // filename should always be a nice clean unix style relative path ct = gtk_label_get_text( GTK_LABEL( m_pFileLabel ) ); - strcat( browsedir,ct ); + strncat( browsedir, ct, sizeof( browsedir ) ); Syn_Printf( MSG_PREFIX "full path: %s\n",browsedir ); // lop off the file part @@ -171,7 +170,7 @@ void CBackgroundDialogPage::Browse(){ void CBackgroundDialogPage::SetPosLabel(){ char s[64]; - snprintf( s, sizeof( s ) - 1, _( "Size/Position (%d,%d) (%d,%d)" ),(int)( m_pImage->m_xmin ), + snprintf( s, sizeof( s ), _( "Size/Position (%d,%d) (%d,%d)" ),(int)( m_pImage->m_xmin ), (int)( m_pImage->m_ymin ),(int)( m_pImage->m_xmax ),(int)( m_pImage->m_ymax ) ); gtk_label_set_text( GTK_LABEL( m_pPosLabel ),s ); } 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 01a34330..552521d7 100644 --- a/contrib/bobtoolz/DBrush.cpp +++ b/contrib/bobtoolz/DBrush.cpp @@ -683,9 +683,9 @@ void DBrush::SaveToFile( FILE *pFile ){ for ( list::const_iterator pp = faceList.begin(); pp != faceList.end(); pp++ ) { - char buffer[512]; + char buffer[720 + PATH_MAX]; - sprintf( buffer, "( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) %s %.0f %.0f %f %f %.0f 0 0 0\n", + snprintf( buffer, sizeof( buffer ), "( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) %s %.0f %.0f %f %f %.0f 0 0 0\n", ( *pp )->points[0][0], ( *pp )->points[0][1], ( *pp )->points[0][2], ( *pp )->points[1][0], ( *pp )->points[1][1], ( *pp )->points[1][2], ( *pp )->points[2][0], ( *pp )->points[2][1], ( *pp )->points[2][2], @@ -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 ee4abf4b..3ffbf274 100644 --- a/contrib/bobtoolz/DTrainDrawer.cpp +++ b/contrib/bobtoolz/DTrainDrawer.cpp @@ -191,7 +191,7 @@ void DTrainDrawer::Draw2D( VIEWTYPE vt ) { void AddSplineControl( const char* control, splinePoint_t* pSP ) { controlPoint_t cp; - strncpy( cp.strName, control, 64 ); + Q_strncpyz( cp.strName, control, sizeof( cp.strName ) ); pSP->m_pointList.push_front( cp ); } @@ -235,8 +235,8 @@ void DTrainDrawer::BuildPaths() { AddSplineControl( control, pSP ); for ( int j = 2;; j++ ) { - char buffer[16]; - sprintf( buffer, "control%i", j ); + char buffer[32]; + snprintf( buffer, sizeof( buffer ), "control%i", j ); e.SpawnString( buffer, NULL, &control ); if ( !control ) { @@ -324,7 +324,7 @@ void DTrainDrawer::BuildPaths() { void DTrainDrawer::AddControlPoint( const char* name, vec_t* origin ){ controlPoint_t* pCP = new controlPoint_t; - strncpy( pCP->strName, name, 64 ); + Q_strncpyz( pCP->strName, name, sizeof( pCP->strName ) ); VectorCopy( origin, pCP->vOrigin ); m_pointList.push_back( pCP ); @@ -333,8 +333,8 @@ void DTrainDrawer::AddControlPoint( const char* name, vec_t* origin ){ splinePoint_t* DTrainDrawer::AddSplinePoint( const char* name, const char* target, vec_t* origin ){ splinePoint_t* pSP = new splinePoint_t; - strncpy( pSP->point.strName, name, 64 ); - strncpy( pSP->strTarget, target, 64 ); + Q_strncpyz( pSP->point.strName, name, sizeof( pSP->point.strName ) ); + Q_strncpyz( pSP->strTarget, target, sizeof( pSP->strTarget ) ); VectorCopy( origin, pSP->point.vOrigin ); m_splineList.push_back( pSP ); 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/DTreePlanter.h b/contrib/bobtoolz/DTreePlanter.h index b3eb8cc5..09c811d2 100644 --- a/contrib/bobtoolz/DTreePlanter.h +++ b/contrib/bobtoolz/DTreePlanter.h @@ -66,7 +66,7 @@ DTreePlanter() { m_world.LoadSelectedBrushes(); char buffer[256]; - GetFilename( buffer, "bt/tp_ent.txt" ); + GetFilename( buffer, "bt/tp_ent.txt", sizeof( buffer ) ); FILE* file = fopen( buffer, "rb" ); if ( file ) { diff --git a/contrib/bobtoolz/bobToolz-GTK.cpp b/contrib/bobtoolz/bobToolz-GTK.cpp index 1cd11552..48a94795 100644 --- a/contrib/bobtoolz/bobToolz-GTK.cpp +++ b/contrib/bobtoolz/bobToolz-GTK.cpp @@ -287,11 +287,11 @@ const char* CSynapseClientBobtoolz::GetInfo(){ return "bobToolz module built " __DATE__ " " RADIANT_VERSION; } -char* GetFilename( char* buffer, const char* filename ) { - strcpy( buffer, g_pSynapseServer->GetModuleFilename( &g_SynapseClient ) ); +char* GetFilename( char* buffer, const char* filename, size_t length ) { + Q_strncpyz( buffer, g_pSynapseServer->GetModuleFilename( &g_SynapseClient ), length ); StripFilename( buffer ); - strcat( buffer, "/" ); - strcat( buffer, filename ); + strncat( buffer, "/", length ); + strncat( buffer, filename, length ); buffer = UnixToDosPath( buffer ); return buffer; } diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp index 768190ec..ee90bdee 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp @@ -130,7 +130,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 ); @@ -152,7 +152,7 @@ bool ValidateTextFloatRange( const char* pData, float min, float max, const char bool ValidateTextIntRange( const char* pData, int min, int max, const char* error_title, int* value ){ char error_buffer[256]; - sprintf( error_buffer, "Please Enter An Integer Between %i and %i", min, max ); + snprintf( error_buffer, sizeof( error_buffer ), "Please Enter An Integer Between %i and %i", min, max ); if ( pData ) { int testNum = atoi( pData ); @@ -793,8 +793,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; @@ -864,8 +864,8 @@ int DoDoorsBox( DoorRS* rs ){ char buffer[256]; GList *listMainTextures = NULL; GList *listTrimTextures = NULL; - LoadGList( GetFilename( buffer, "plugins/bt/door-tex.txt" ), &listMainTextures ); - LoadGList( GetFilename( buffer, "plugins/bt/door-tex-trim.txt" ), &listTrimTextures ); + LoadGList( GetFilename( buffer, "plugins/bt/door-tex.txt", sizeof( buffer ) ), &listMainTextures ); + LoadGList( GetFilename( buffer, "plugins/bt/door-tex-trim.txt", sizeof( buffer ) ), &listTrimTextures ); vbox = gtk_vbox_new( FALSE, 10 ); gtk_container_add( GTK_CONTAINER( window ), vbox ); @@ -1031,8 +1031,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; @@ -1614,8 +1614,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 596c5ac2..9a8ff62c 100644 --- a/contrib/bobtoolz/funchandlers-GTK.cpp +++ b/contrib/bobtoolz/funchandlers-GTK.cpp @@ -55,13 +55,13 @@ DTreePlanter* g_TreePlanter = NULL; //========================// void LoadLists(){ - char buffer[256]; + char buffer[PATH_MAX]; if ( !el1Loaded ) { - el1Loaded = LoadExclusionList( GetFilename( buffer, "bt/bt-el1.txt" ), &exclusionList ); + el1Loaded = LoadExclusionList( GetFilename( buffer, "bt/bt-el1.txt", sizeof( buffer ) ), &exclusionList ); } if ( !el2Loaded ) { - el2Loaded = LoadExclusionList( GetFilename( buffer, "bt/bt-el2.txt" ), &exclusionList_Face ); + el2Loaded = LoadExclusionList( GetFilename( buffer, "bt/bt-el2.txt", sizeof( buffer ) ), &exclusionList_Face ); } } @@ -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 4ae16b42..0f45bb1c 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(){ @@ -140,7 +140,7 @@ void Sys_ERROR( const char* text, ... ){ char buf[32768]; va_start( argptr,text ); - vsprintf( buf, text,argptr ); + vsnprintf( buf, sizeof( buf ), text, argptr ); va_end( argptr ); Sys_FPrintf( SYS_ERR, "BobToolz::ERROR->%s", buf ); @@ -152,7 +152,7 @@ void Sys_ERROR( const char* text, ... ){ char buf[32768]; va_start (argptr,text); - vsprintf (buf, text,argptr); + vsnprintf (buf, sizeof( buf ), text, argptr); va_end (argptr); g_FuncTable.m_pfnSysMsg ( buf ); @@ -248,19 +248,19 @@ bool Q_Exec( const char *pCmd, bool bCreateConsole ){ #endif void StartBSP(){ - char exename[256]; - GetFilename( exename, "q3map" ); + char exename[PATH_MAX]; + GetFilename( exename, "q3map", sizeof( exename ) ); UnixToDosPath( exename ); // do we want this done in linux version? char mapname[256]; const char *pn = g_FuncTable.m_pfnReadProjectKey( "mapspath" ); - strcpy( mapname, pn ); - strcat( mapname, "/ac_prt.map" ); + Q_strncpyz( mapname, pn, sizeof( mapname ) ); + strncat( mapname, "/ac_prt.map", sizeof( mapname ) ); UnixToDosPath( mapname ); char command[1024]; - sprintf( command, "%s -nowater -fulldetail %s", exename, mapname ); + snprintf( command, sizeof( command ), "%s -nowater -fulldetail %s", exename, mapname ); Q_Exec( command, TRUE ); } @@ -272,11 +272,11 @@ void BuildMiniPrt( list* exclusionList ){ DEntity world; - char buffer[128]; + char buffer[PATH_MAX]; const char *pn = g_FuncTable.m_pfnReadProjectKey( "mapspath" ); - strcpy( buffer, pn ); - strcat( buffer, "/ac_prt.map" ); + Q_strncpyz( buffer, pn, sizeof( buffer ) ); + strncat( buffer, "/ac_prt.map", sizeof( buffer ) ); FILE* pFile = fopen( buffer, "w" ); // ahem, thx rr2 @@ -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/misc.h b/contrib/bobtoolz/misc.h index 7774a3f2..5d96b2c3 100644 --- a/contrib/bobtoolz/misc.h +++ b/contrib/bobtoolz/misc.h @@ -37,7 +37,7 @@ entity_s* FindEntityFromTargetname( const char* targetname, int* entNum ); char* UnixToDosPath( char* path ); -char* GetFilename( char* buffer, const char* filename ); +char* GetFilename( char* buffer, const char* filename, size_t length ); char* GetGameFilename( char* buffer, const char* filename ); float Determinant3x3( float a1, float a2, float a3, 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 07677e30..15785ac5 100644 --- a/contrib/camera/dialogs.cpp +++ b/contrib/camera/dialogs.cpp @@ -220,10 +220,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 ); @@ -336,14 +336,14 @@ static void RefreshEventList( void ){ for ( i = 0; i < GetCurrentCam()->GetCam()->numEvents(); i++ ) { char rowbuf[3][128], *row[3]; // FIXME: sort by time? - sprintf( rowbuf[0], "%li", GetCurrentCam()->GetCam()->getEvent( i )->getTime() ); row[0] = rowbuf[0]; - strncpy( rowbuf[1], GetCurrentCam()->GetCam()->getEvent( i )->typeStr(), sizeof( rowbuf[0] ) ); row[1] = rowbuf[1]; - strncpy( rowbuf[2], GetCurrentCam()->GetCam()->getEvent( i )->getParam(), sizeof( rowbuf[1] ) ); row[2] = rowbuf[2]; + snprintf( rowbuf[0], sizeof( rowbuf[0] ), "%li", GetCurrentCam()->GetCam()->getEvent( i )->getTime() ); row[0] = rowbuf[0]; + Q_strncpyz( rowbuf[1], GetCurrentCam()->GetCam()->getEvent( i )->typeStr(), sizeof( rowbuf[0] ) ); row[1] = rowbuf[1]; + Q_strncpyz( rowbuf[2], GetCurrentCam()->GetCam()->getEvent( i )->getParam(), sizeof( rowbuf[1] ) ); row[2] = rowbuf[2]; gtk_clist_append( GTK_CLIST( g_pEventsList ), row ); } // 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 ); @@ -511,7 +511,7 @@ static gint ci_add_target( GtkWidget *widget, 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 ); // -------------------------- // @@ -721,10 +721,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 ); diff --git a/contrib/camera/funchandlers.cpp b/contrib/camera/funchandlers.cpp index 8f568877..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 ); @@ -99,7 +99,7 @@ void DoLoadCamera(){ CAMERA_ExtractFilePath( firstCam->GetFileName(), basepath ); } else{ - strcpy( basepath, g_FuncTable.m_pfnGetGamePath() ); + Q_strncpyz( basepath, g_FuncTable.m_pfnGetGamePath(), sizeof( basepath ) ); } const gchar *filename = g_FuncTable.m_pfnFileDialog( (GtkWidget *)g_pRadiantWnd, TRUE, "Open Camera File", basepath, "camera", NULL ); @@ -117,7 +117,7 @@ void DoLoadCamera(){ if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) { char error[PATH_MAX + 64]; FreeCam( cam ); - sprintf( error, "Camera file \'%s\' is already loaded", fullpathtofile ); + snprintf( error, sizeof( error ), "Camera file \'%s\' is already loaded", fullpathtofile ); g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL ); //g_free( filename ); return; @@ -135,7 +135,7 @@ void DoLoadCamera(){ else { char error[PATH_MAX + 64]; FreeCam( cam ); - sprintf( error, "An error occured during the loading of \'%s\'", fullpathtofile ); + snprintf( error, sizeof( error ), "An error occured during the loading of \'%s\'", fullpathtofile ); g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL ); } @@ -158,7 +158,7 @@ void DoSaveCamera() { CAMERA_ExtractFilePath( GetCurrentCam()->GetFileName(), basepath ); } else{ - strcpy( basepath, g_FuncTable.m_pfnGetGamePath() ); + Q_strncpyz( basepath, g_FuncTable.m_pfnGetGamePath(), sizeof( basepath ) ); } const gchar *filename = g_FuncTable.m_pfnFileDialog( (void *)g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera", NULL ); @@ -171,7 +171,7 @@ void DoSaveCamera() { // File dialog from windows (and maybe the gtk one from radiant) doesn't handle default extensions properly. // Add extension and check again if file exists if ( strcmp( fullpathtofile + ( strlen( fullpathtofile ) - 7 ), ".camera" ) ) { - strcat( fullpathtofile, ".camera" ); + strncat( fullpathtofile, ".camera", sizeof( fullpathtofile ) ); if ( FileExists( fullpathtofile ) ) { if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "File already exists.\nOverwrite?", "Save Camera File", MB_YESNO, NULL ) == IDNO ) { @@ -191,7 +191,7 @@ void DoSaveCamera() { } else if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) { char error[PATH_MAX + 64]; - sprintf( error, "Camera file \'%s\' is currently loaded by GtkRadiant.\nPlease select a different filename.", fullpathtofile ); + snprintf( error, sizeof( error ), "Camera file \'%s\' is currently loaded by GtkRadiant.\nPlease select a different filename.", fullpathtofile ); g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", MB_OK, NULL ); return; } @@ -213,14 +213,14 @@ void DoUnloadCamera() { if ( !GetCurrentCam()->HasBeenSaved() ) { char buf[PATH_MAX + 64]; - sprintf( buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() ); + snprintf( buf, sizeof( buf ), "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() ); if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) { DoSaveCamera(); } } else if ( GetCurrentCam()->HasBeenSaved() == 2 ) { char buf[PATH_MAX + 64]; - sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() ); + snprintf( buf, sizeof( buf ), "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() ); if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) { DoSaveCamera(); } diff --git a/contrib/camera/misc.cpp b/contrib/camera/misc.cpp index 75e885de..b8368458 100644 --- a/contrib/camera/misc.cpp +++ b/contrib/camera/misc.cpp @@ -31,7 +31,7 @@ void Sys_ERROR( char* text, ... ){ char buf[32768]; va_start( argptr,text ); - vsprintf( buf, text,argptr ); + vsnprintf( buf, sizeof( buf ), text, argptr ); va_end( argptr ); Sys_FPrintf( SYS_ERR, "Camera::ERROR->%s", buf ); @@ -114,7 +114,7 @@ void CDECL Com_Error( int level, const char *error, ... ){ char buf[32768]; va_start( argptr,error ); - vsprintf( buf, error,argptr ); + vsnprintf( buf, sizeof( buf ), error, argptr ); va_end( argptr ); Sys_FPrintf( SYS_ERR, "Camera::ERROR->%s", buf ); @@ -125,7 +125,7 @@ void CDECL Com_Printf( const char* msg, ... ){ char buf[32768]; va_start( argptr,msg ); - vsprintf( buf, msg,argptr ); + vsnprintf( buf, sizeof( buf ), msg, argptr ); va_end( argptr ); Sys_Printf( "Camera::%s", buf ); @@ -137,7 +137,7 @@ void CDECL Com_DPrintf( const char* msg, ... ){ char buf[32768]; va_start( argptr,msg ); - vsprintf( buf, msg,argptr ); + vsnprintf( buf, sizeof( buf ), msg, argptr ); va_end( argptr ); Sys_Printf( "Camera::%s", buf ); diff --git a/contrib/gtkgensurf/bitmap.cpp b/contrib/gtkgensurf/bitmap.cpp index b49c6ca9..24358832 100644 --- a/contrib/gtkgensurf/bitmap.cpp +++ b/contrib/gtkgensurf/bitmap.cpp @@ -442,7 +442,7 @@ bool OpenBitmap(){ g_print( "failed to load file gbmp %s\n",gbmp.name ); char Text[256]; - sprintf( Text, "Error opening %s", gbmp.name ); + snprintf( Text, sizeof( Text ), "Error opening %s", gbmp.name ); g_FuncTable.m_pfnMessageBox( g_pWnd, Text, "Bitmap", MB_ICONEXCLAMATION, NULL ); strcpy( gbmp.name, "" ); } 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 b4151a24..9652068f 100644 --- a/contrib/gtkgensurf/gendlgs.cpp +++ b/contrib/gtkgensurf/gendlgs.cpp @@ -281,32 +281,32 @@ static void SetDlgValues( int tab ){ gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( wave_radios[WaveType] ), TRUE ); gtk_spin_button_set_value( GTK_SPIN_BUTTON( g_object_get_data( G_OBJECT( g_pWnd ), "random" ) ), RandomSeed ); - sprintf( Text, RForm, WaveLength ); + snprintf( Text, sizeof( Text ), RForm, WaveLength ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "wavelength" ) ), Text ); - sprintf( Text, RForm, Amplitude ); + snprintf( Text, sizeof( Text ), RForm, Amplitude ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "amplitude" ) ), Text ); - sprintf( Text, RForm, Roughness ); + snprintf( Text, sizeof( Text ), RForm, Roughness ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "roughness" ) ), Text ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( g_object_get_data ( G_OBJECT( g_pWnd ), "main_antialiasing" ) ), Antialiasing ); break; case EXTENTS_TAB: - sprintf( Text,RForm,Hll ); + snprintf( Text, sizeof( Text ), RForm, Hll ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "hmin" ) ), Text ); - sprintf( Text,RForm,Vll ); + snprintf( Text, sizeof( Text ), RForm, Vll ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "vmin" ) ), Text ); - sprintf( Text,RForm,Hur ); + snprintf( Text, sizeof( Text ), RForm, Hur ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "hmax" ) ), Text ); - sprintf( Text,RForm,Vur ); + snprintf( Text, sizeof( Text ), RForm, Vur ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "vmax" ) ), Text ); - sprintf( Text,RForm,Z00 ); + snprintf( Text, sizeof( Text ), RForm, Z00 ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "z00" ) ), Text ); - sprintf( Text,RForm,Z01 ); + snprintf( Text, sizeof( Text ), RForm, Z01 ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "z01" ) ), Text ); - sprintf( Text,RForm,Z10 ); + snprintf( Text, sizeof( Text ), RForm, Z10 ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "z10" ) ), Text ); - sprintf( Text,RForm,Z11 ); + snprintf( Text, sizeof( Text ), RForm, Z11 ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "z11" ) ), Text ); gtk_spin_button_set_value( GTK_SPIN_BUTTON( g_object_get_data( G_OBJECT( g_pWnd ), "nh" ) ), NH ); gtk_spin_button_set_value( GTK_SPIN_BUTTON( g_object_get_data( G_OBJECT( g_pWnd ), "nv" ) ), NV ); @@ -386,9 +386,9 @@ static void SetDlgValues( int tab ){ case BITMAP_TAB: gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "bmp_file" ) ), gbmp.name ); - sprintf( Text,"%g",gbmp.black_value ); + snprintf( Text, sizeof( Text ), "%g", gbmp.black_value ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "bmp_black" ) ), Text ); - sprintf( Text,"%g",gbmp.white_value ); + snprintf( Text, sizeof( Text ), "%g", gbmp.white_value ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "bmp_white" ) ), Text ); break; @@ -401,13 +401,13 @@ static void SetDlgValues( int tab ){ gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "texture3" ) ), Texture[Game][2] ); gtk_spin_button_set_value( GTK_SPIN_BUTTON( g_object_get_data( G_OBJECT( g_pWnd ), "tex_slant" ) ), SlantAngle ); - sprintf( Text,RForm,TexOffset[0] ); + snprintf( Text, sizeof( Text ), RForm, TexOffset[0] ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "texoffsetx" ) ), Text ); - sprintf( Text,RForm,TexOffset[1] ); + snprintf( Text, sizeof( Text ), RForm, TexOffset[1] ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "texoffsety" ) ), Text ); - sprintf( Text,RForm,TexScale[0] ); + snprintf( Text, sizeof( Text ), RForm, TexScale[0] ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "texscalex" ) ), Text ); - sprintf( Text,RForm,TexScale[1] ); + snprintf( Text, sizeof( Text ), RForm, TexScale[1] ); gtk_entry_set_text( GTK_ENTRY( g_object_get_data( G_OBJECT( g_pWnd ), "texscaley" ) ), Text ); CHECK_WIDGET( "detail", UseDetail ); @@ -727,14 +727,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_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_page( GTK_NOTEBOOK( notebook ), EXTENTS_TAB ); return; @@ -883,9 +883,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(); } @@ -901,12 +901,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(); @@ -915,7 +915,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 ) ); @@ -936,7 +936,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 ); } @@ -1006,7 +1006,7 @@ static void fix_freeall( GtkWidget *widget, gpointer data ){ } void vertex_selected(){ - char Text[32]; + char Text[64]; int k; SetupControls(); @@ -1032,9 +1032,9 @@ 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 ); - sprintf( Text,"%.5g",xyz[Vertex[0].i][Vertex[0].j].rate ); + 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 ); for ( k = 0; k < NumVerticesSelected; k++ ) @@ -1071,7 +1071,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 ){ @@ -2230,8 +2230,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: */ @@ -2315,7 +2315,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 f4336982..7d24f1eb 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 17160aa9..292e623a 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 ) ) { @@ -353,7 +353,7 @@ char *va( const char *format, ... ){ static char string[1024]; va_start( argptr, format ); - vsprintf( string, format,argptr ); + vsnprintf( string, sizeof( string ), format, argptr ); va_end( argptr ); return string; @@ -423,22 +423,22 @@ void SaveSetup( GtkWidget *parent ){ g_FuncTable.m_pfnProfileGetDirectory(), "gtkgensurf", NULL ); if ( name != NULL ) { - char key[32], text[32]; + char key[32], text[128]; int i, j; 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 ); - sprintf( text,"%g %g %g", xyz[i][j].fixed_value, xyz[i][j].range, xyz[i][j].rate ); + 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..1220b4cb 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); if ((_len) > 0) (_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 c48f664a..2d5c4469 100644 --- a/contrib/gtkgensurf/view.cpp +++ b/contrib/gtkgensurf/view.cpp @@ -320,14 +320,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/hydratoolz/plugin.cpp b/contrib/hydratoolz/plugin.cpp index 79bba252..5932f8e2 100644 --- a/contrib/hydratoolz/plugin.cpp +++ b/contrib/hydratoolz/plugin.cpp @@ -146,7 +146,7 @@ GSList *AddToWadList( GSList *wadlist, const char *shadername, const char *wad ) } else { - Sys_Printf( "HydraToolz: WARNING: Unknown wad file for shader %s\n",shadername ); + Sys_FPrintf( SYS_WRN, "HydraToolz: WARNING: Unknown wad file for shader %s\n",shadername ); return wadlist; } @@ -199,7 +199,7 @@ void UpdateWadKeyPair( void ){ for ( pEpair = pEntity->epairs; pEpair != NULL; pEpair = pEpair->next ) { if ( stricmp( pEpair->key,"wad" ) == 0 ) { - strcpy( wads,pEpair->value ); + Q_strncpyz( wads, pEpair->value, sizeof( wads ) ); HYDRA_ConvertDOSToUnixName( wads,wads ); Sys_Printf( "HydraToolz: Current wad key is \"%s\"!\n",wads ); @@ -295,18 +295,18 @@ void UpdateWadKeyPair( void ){ else { if ( wads[0] ) { - strcat( wads,";" ); + strncat( wads, ";", sizeof( wads ) ); } actualwad = vfsGetFullPath( (char *)wadlist->data, 0, 0 ); if ( actualwad ) { - strcat( wads, actualwad ); + strncat( wads, actualwad, sizeof( wads ) ); } else { Sys_FPrintf( SYS_WRN, "WARNING: could not locate wad file %s\n",(char *)wadlist->data ); - strcat( wads, (char *)wadlist->data ); + strncat( wads, (char *)wadlist->data, sizeof( wads ) ); } } diff --git a/contrib/prtview/ConfigDialog.cpp b/contrib/prtview/ConfigDialog.cpp index 2f315190..0785603b 100644 --- a/contrib/prtview/ConfigDialog.cpp +++ b/contrib/prtview/ConfigDialog.cpp @@ -99,17 +99,17 @@ static int DoColor( COLORREF *c ){ } 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 ); } @@ -117,7 +117,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 ); } @@ -125,7 +125,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/contrib/prtview/LoadPortalFileDialog.cpp b/contrib/prtview/LoadPortalFileDialog.cpp index 4b25ce50..0e81165a 100644 --- a/contrib/prtview/LoadPortalFileDialog.cpp +++ b/contrib/prtview/LoadPortalFileDialog.cpp @@ -159,11 +159,11 @@ int DoLoadPortalFileDialog(){ gtk_widget_set_usize( button, 60, -2 ); char *fn = g_FuncTable.m_pfnGetMapName(); - strcpy( portals.fn, fn ); + Q_strncpyz( portals.fn, fn, sizeof( portals.fn ) ); fn = strrchr( portals.fn, '.' ); if ( fn != NULL ) { *fn = '\0'; - strcat( portals.fn, ".prt" ); + strncat( portals.fn, ".prt", sizeof( portals.fn ) ); } gtk_entry_set_text( GTK_ENTRY( entry ), portals.fn ); diff --git a/contrib/prtview/prtview.cpp b/contrib/prtview/prtview.cpp index 65ffd14d..4d30bea8 100644 --- a/contrib/prtview/prtview.cpp +++ b/contrib/prtview/prtview.cpp @@ -55,6 +55,8 @@ static char INIfn[NAME_MAX]; #define CLIP_RANGE "ClipRange" #define CLIP "Clip" +void *g_pMainWidget = NULL; + void InitInstance(){ #ifdef _WIN32 char fn[_MAX_PATH]; @@ -67,15 +69,15 @@ void InitInstance(){ _splitpath( fn, fn_drive, fn_dir, fn_name, fn_ext ); - strcpy( INIfn, fn_drive ); - strcat( INIfn, fn_dir ); - strcat( INIfn, fn_name ); - strcat( INIfn, ".ini" ); + Q_strncpyz( INIfn, fn_drive, sizeof( INIfn ) ); + strncat( INIfn, fn_dir, sizeof( INIfn ) ); + strncat( INIfn, fn_name, sizeof( INIfn ) ); + strncat( INIfn, ".ini", sizeof( INIfn ) ); #else // if def __linux__ - strcpy( INIfn, g_get_home_dir() ); - strcat( INIfn, "/.radiant/" ); - strcat( INIfn, RADIANT_VERSION ); - strcat( INIfn, "/prtview.ini" ); + Q_strncpyz( INIfn, g_get_home_dir(), sizeof( INIfn ) ); + strncat( INIfn, "/.radiant/", sizeof( INIfn ) ); + strncat( INIfn, RADIANT_VERSION, sizeof( INIfn ) ); + strncat( INIfn, "/prtview.ini", sizeof( INIfn ) ); #endif portals.show_2d = INIGetInt( RENDER_2D, FALSE ) ? true : false; @@ -166,7 +168,7 @@ _QERQglTable g_QglTable; #if defined( __linux__ ) || defined( __APPLE__ ) -static bool read_var( const char *filename, const char *section, const char *key, char *value ){ +static bool read_var( const char *filename, const char *section, const char *key, char *value, size_t length ){ char line[1024], *ptr; FILE *rc; @@ -199,7 +201,7 @@ static bool read_var( const char *filename, const char *section, const char *key *ptr = '\0'; if ( strcmp( line, key ) == 0 ) { - strcpy( value, ptr + 1 ); + Q_strncpyz( value, ptr + 1, length ); fclose( rc ); while ( value[strlen( value ) - 1] == 10 || @@ -317,7 +319,7 @@ int INIGetInt( const char *key, int def ){ #if defined( __linux__ ) || defined( __APPLE__ ) char value[1024]; - if ( read_var( INIfn, CONFIG_SECTION, key, value ) ) { + if ( read_var( INIfn, CONFIG_SECTION, key, value, sizeof( value ) ) ) { return atoi( value ); } else{ @@ -332,10 +334,10 @@ void INISetInt( const char *key, int val, const char *comment /* = NULL */ ){ char s[1000]; if ( comment ) { - sprintf( s, "%d ; %s", val, comment ); + snprintf( s, sizeof( s ), "%d ; %s", val, comment ); } else{ - sprintf( s, "%d", val ); + snprintf( s, sizeof( s ), "%d", val ); } #if defined( __linux__ ) || defined( __APPLE__ ) save_var( INIfn, CONFIG_SECTION, key, s ); @@ -387,7 +389,7 @@ extern "C" const char* QERPlug_GetCommandList(){ char buf[32768]; va_start (argptr,text); - vsprintf (buf, text, argptr); + vsnprintf (buf, sizeof( buf ), text, argptr); va_end (argptr); g_FuncTable.m_pfnSysMsg (buf); diff --git a/include/qerplugin.h b/include/qerplugin.h index ee24c29c..189a4aee 100644 --- a/include/qerplugin.h +++ b/include/qerplugin.h @@ -33,6 +33,12 @@ #include #include +#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 // TTimo // ideally the plugin API would be UI toolkit independent, but removing the dependency with GLib seems tricky right now.. #include diff --git a/libs/cmdlib.h b/libs/cmdlib.h index 782b602b..560fdef1 100644 --- a/libs/cmdlib.h +++ b/libs/cmdlib.h @@ -49,14 +49,26 @@ #define Q_mkdir( a,b ) mkdir( a,b ) #endif -void DefaultExtension( char *path, char *extension ); -void DefaultPath( char *path, char *basepath ); +#if defined(_MSC_VER) && _MSC_VER<1900 && !(defined safe_malloc) +void *safe_malloc( size_t size ); +void *safe_malloc_info( size_t size, char* info ); +#endif + +#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); if ((_len) > 0) (_dst)[(_len) - 1] = 0; } while( 0 ) +#endif + +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 ); +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 b27919ff..2275fa76 100644 --- a/libs/cmdlib/cmdlib.cpp +++ b/libs/cmdlib/cmdlib.cpp @@ -51,14 +51,14 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo case 0: // always concat the command on linux if ( cmd ) { - strcpy( fullcmd, cmd ); + Q_strncpyz( fullcmd, cmd, sizeof( fullcmd ) ); } else{ fullcmd[0] = '\0'; } if ( cmdline ) { - strcat( fullcmd, " " ); - strcat( fullcmd, cmdline ); + strncat( fullcmd, " ", sizeof( fullcmd ) ); + strncat( fullcmd, cmdline, sizeof( fullcmd ) ); } pCmd = fullcmd; while ( *pCmd == ' ' ) @@ -159,7 +159,7 @@ int Q_filelength( FILE *f ){ return end; } -void DefaultExtension( char *path, char *extension ){ +void DefaultExtension( char *path, char *extension, size_t length ){ char *src; // // if path doesn't have a .EXT, append extension @@ -175,18 +175,18 @@ void DefaultExtension( char *path, char *extension ){ src--; } - strcat( path, extension ); + strncat( path, extension, length ); } -void DefaultPath( char *path, char *basepath ){ - char temp[128]; +void DefaultPath( char *path, const char *basepath, size_t length ){ + char temp[PATH_MAX]; if ( path[0] == PATHSEPERATOR ) { return; // absolute path location } - strcpy( temp,path ); - strcpy( path,basepath ); - strcat( path,temp ); + Q_strncpyz( temp, path, sizeof( temp ) ); + Q_strncpyz( path, basepath, length ); + strncat( path, temp, length ); } @@ -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 ){ +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 ){ return; } - strcpy( dest,src ); + 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/l_net/l_net.c b/libs/l_net/l_net.c index 385751b2..4fc23b6e 100644 --- a/libs/l_net/l_net.c +++ b/libs/l_net/l_net.c @@ -48,7 +48,7 @@ void WinPrint( char *str, ... ){ char text[4096]; va_start( argptr,str ); - vsprintf( text, str, argptr ); + vsnprintf( text, sizeof( text ), str, argptr ); va_end( argptr ); printf("%s", text ); diff --git a/libs/picomodel/picointernal.c b/libs/picomodel/picointernal.c index d4fd8b44..cd083cc8 100644 --- a/libs/picomodel/picointernal.c +++ b/libs/picomodel/picointernal.c @@ -263,7 +263,7 @@ void _pico_printf( int level, const char *format, ... ){ /* format string */ va_start( argptr,format ); - vsprintf( str,format,argptr ); + vsnprintf( str, sizeof( str ), format, argptr ); va_end( argptr ); /* remove linefeeds */ @@ -629,7 +629,7 @@ char *_pico_nopath( const char *path ){ * or filepath's filename portion. the given 'path' *is* * altered. leave 'ext' empty to remove extension. -sea */ -char *_pico_setfext( char *path, const char *ext ){ +char *_pico_setfext( char *path, const char *ext, size_t length ){ char *src; int remfext = 0; @@ -660,7 +660,7 @@ char *_pico_setfext( char *path, const char *ext ){ break; } } - strcat( path,ext ); + strncat( path, ext, length ); return path; } diff --git a/libs/picomodel/picointernal.h b/libs/picomodel/picointernal.h index 12b8cd7c..540dd1b9 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); if ((_len) > 0) (_dst)[(_len) - 1] = 0; } while( 0 ) +#endif /* os dependant replacements */ #if WIN32 || _WIN32 @@ -132,7 +138,7 @@ char *_pico_stristr( char *str, const char *substr ); void _pico_unixify( char *path ); int _pico_nofname( const char *path, char *dest, int destSize ); char *_pico_nopath( const char *path ); -char *_pico_setfext( char *path, const char *ext ); +char *_pico_setfext( char *path, const char *ext, size_t length ); int _pico_getline( char *buf, int bufsize, char *dest, int destsize ); char *_pico_strlwr( char *str ); diff --git a/libs/picomodel/picomodel.c b/libs/picomodel/picomodel.c index 767fc74f..946ec96d 100644 --- a/libs/picomodel/picomodel.c +++ b/libs/picomodel/picomodel.c @@ -212,11 +212,12 @@ picoModel_t *PicoLoadModel( char *fileName, int frameNum ){ /* apply model remappings from .remap */ if ( strlen( modelFileName ) ) { /* alloc copy of model file name */ - remapFileName = _pico_alloc( strlen( modelFileName ) + 20 ); + size_t length = strlen( modelFileName ) + 20; + remapFileName = _pico_alloc( length ); if ( remapFileName != NULL ) { /* copy model file name and change extension */ - strcpy( remapFileName, modelFileName ); - _pico_setfext( remapFileName, "remap" ); + Q_strncpyz( remapFileName, modelFileName, length ); + _pico_setfext( remapFileName, "remap", length ); /* try to remap model; we don't handle the result */ PicoRemapModel( model, remapFileName ); @@ -509,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 64b77fe6..f00bcddd 100644 --- a/libs/picomodel/pm_3ds.c +++ b/libs/picomodel/pm_3ds.c @@ -421,23 +421,23 @@ static int GetMeshShader( T3dsLoaderPers *pers ){ char *name; /* copy map name to local buffer */ - strcpy( mapName,mapNamePtr ); + Q_strncpyz( mapName, mapNamePtr, sizeof( mapName ) ); /* extract file name */ name = _pico_nopath( mapName ); - strncpy( temp, name, sizeof( temp ) ); + Q_strncpyz( temp, name, sizeof( temp ) ); /* remove file extension */ /* name = _pico_setfext( name,"" ); */ /* assign default name if no name available */ if ( strlen( temp ) < 1 ) { - strcpy( temp,pers->basename ); + 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 */ @@ -730,9 +730,8 @@ static picoModel_t *_3ds_load( PM_PARAMS_LOAD ){ return NULL; } /* get model's base name (eg. jeep from c:\models\jeep.3ds) */ - memset( basename,0,sizeof( basename ) ); - strncpy( basename,_pico_nopath( fileName ),sizeof( basename ) ); - _pico_setfext( basename,"" ); + Q_strncpyz( basename, _pico_nopath( fileName ), sizeof( basename ) ); + _pico_setfext( basename, "", sizeof( basename ) ); /* initialize persistant vars (formerly static) */ pers.model = model; diff --git a/libs/picomodel/pm_ase.c b/libs/picomodel/pm_ase.c index dc31dd5f..491d0cb8 100644 --- a/libs/picomodel/pm_ase.c +++ b/libs/picomodel/pm_ase.c @@ -400,7 +400,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ continue; } /* remember node name */ - if ( !_pico_stricmp( p->token,"*node_name" ) ) { + if ( !_pico_stricmp( p->token, "*node_name" ) ) { /* read node name */ char *ptr = _pico_parse( p,0 ); if ( ptr == NULL ) { @@ -408,10 +408,10 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ } /* remember node name */ - strncpy( lastNodeName,ptr,sizeof( lastNodeName ) ); + Q_strncpyz( lastNodeName, ptr, sizeof( lastNodeName ) ); } /* model mesh (originally contained within geomobject) */ - else if ( !_pico_stricmp( p->token,"*mesh" ) ) { + else if ( !_pico_stricmp( p->token, "*mesh" ) ) { /* finish existing surface */ //_ase_make_surface( model, &surface ); _ase_submit_triangles( surface, model,materials,faces ); @@ -796,12 +796,13 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ } /* parse material name */ else if ( !_pico_stricmp( p->token,"*material_name" ) ) { - char* name = _pico_parse( p,0 ); + char* name = _pico_parse( p, 0 ); if ( name == NULL ) { _ase_error_return( "Missing material name" ); } - strcpy( materialName, name ); + Q_strncpyz( materialName, name, sizeof( materialName ) ); + materialName[sizeof( materialName ) - 1] = 0; /* skip rest and continue with next token */ _pico_parse_skip_rest( p ); continue; diff --git a/libs/picomodel/pm_fm.c b/libs/picomodel/pm_fm.c index a4251337..9b2181fa 100644 --- a/libs/picomodel/pm_fm.c +++ b/libs/picomodel/pm_fm.c @@ -350,7 +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 ); + Q_strncpyz( skinname, (char *) fm.fm_skin, FM_SKINPATHSIZE ); #ifdef FM_VERBOSE_DBG // Print out md2 values @@ -358,7 +358,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ){ #endif // detox Skin name - _pico_setfext( skinname, "" ); + _pico_setfext( skinname, "", sizeof( skinname ) ); _pico_unixify( skinname ); /* create new pico model */ diff --git a/libs/picomodel/pm_lwo.c b/libs/picomodel/pm_lwo.c index f1d82dd9..2930cfe0 100644 --- a/libs/picomodel/pm_lwo.c +++ b/libs/picomodel/pm_lwo.c @@ -234,8 +234,8 @@ static picoModel_t *_lwo_load( PM_PARAMS_LOAD ){ } /* detox and set shader name */ - strncpy( name, surface->name, sizeof( name ) ); - _pico_setfext( name, "" ); + 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 c1011cfb..15cf7316 100644 --- a/libs/picomodel/pm_md2.c +++ b/libs/picomodel/pm_md2.c @@ -431,7 +431,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ){ } // set Skin Name - strncpy( skinname, (char *) ( bb + md2->ofsSkins ), MD2_MAX_SKINNAME ); + 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 ); @@ -439,7 +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 ); + Q_strncpyz( path, fileName, MD2_MAX_SKINNAME ); + for ( i = MD2_MAX_SKINNAME; i--; ) { // skip filename if ( path[i] == '/' || path[i] == '\\' ) { @@ -448,14 +449,14 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ){ path[i] = '\0'; } strncat( path, &skinname[1], MD2_MAX_SKINNAME ); - strncpy( skinname, path, MD2_MAX_SKINNAME ); + 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 ); } // detox Skin name - _pico_setfext( skinname, "" ); + _pico_setfext( skinname, "", sizeof( skinname ) ); _pico_unixify( skinname ); /* create new pico model */ diff --git a/libs/picomodel/pm_md3.c b/libs/picomodel/pm_md3.c index 94f7a8f4..e64cbef5 100644 --- a/libs/picomodel/pm_md3.c +++ b/libs/picomodel/pm_md3.c @@ -344,7 +344,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ){ /* detox and set shader name */ shader = (md3Shader_t*) ( (picoByte_t*) surface + surface->ofsShaders ); - _pico_setfext( shader->name, "" ); + _pico_setfext( shader->name, "", sizeof( shader->name ) ); _pico_unixify( shader->name ); PicoSetShaderName( picoShader, shader->name ); diff --git a/libs/picomodel/pm_mdc.c b/libs/picomodel/pm_mdc.c index 2e4849fb..a054e639 100644 --- a/libs/picomodel/pm_mdc.c +++ b/libs/picomodel/pm_mdc.c @@ -644,7 +644,7 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ){ /* detox and set shader name */ shader = (mdcShader_t*) ( (picoByte_t*) surface + surface->ofsShaders ); - _pico_setfext( shader->name, "" ); + _pico_setfext( shader->name, "", sizeof( shader->name ) ); _pico_unixify( shader->name ); PicoSetShaderName( picoShader, shader->name ); diff --git a/libs/picomodel/pm_obj.c b/libs/picomodel/pm_obj.c index 2f6e93c4..baa9d97d 100644 --- a/libs/picomodel/pm_obj.c +++ b/libs/picomodel/pm_obj.c @@ -640,7 +640,7 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){ /* some obj exporters feel like they don't need to */ /* supply a group name. so we gotta handle it here */ #if 1 - strcpy( p->token,"default" ); + strcpy( p->token, "default" ); groupName = p->token; #else _obj_error_return( "Invalid or missing group name" ); 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/q_parse.cpp b/libs/splines/q_parse.cpp index 324cd29f..8935e341 100644 --- a/libs/splines/q_parse.cpp +++ b/libs/splines/q_parse.cpp @@ -100,7 +100,7 @@ void Com_ScriptError( const char *msg, ... ) { char string[32000]; va_start( argptr, msg ); - vsprintf( string, msg,argptr ); + vsnprintf( string, sizeof( string ), msg, argptr ); va_end( argptr ); Com_Error( ERR_DROP, "File %s, line %i: %s", pi->parseFile, pi->lines, string ); @@ -111,7 +111,7 @@ void Com_ScriptWarning( const char *msg, ... ) { char string[32000]; va_start( argptr, msg ); - vsprintf( string, msg,argptr ); + vsnprintf( string, sizeof( string ), msg, argptr ); va_end( argptr ); Com_Printf( "File %s, line %i: %s", pi->parseFile, pi->lines, string ); diff --git a/libs/splines/q_shared.cpp b/libs/splines/q_shared.cpp index fba03871..a0b0cdaf 100644 --- a/libs/splines/q_shared.cpp +++ b/libs/splines/q_shared.cpp @@ -472,7 +472,7 @@ int Com_ParseInfos( const char *buf, int max, char infos[][MAX_INFO_STRING] ) { if ( !token[0] ) { token = ""; } - Info_SetValueForKey( infos[count], key, token ); + Info_SetValueForKey( infos[count], key, token, sizeof( infos[count] ) ); } count++; } @@ -695,7 +695,7 @@ void QDECL Com_sprintf( char *dest, int size, const char *fmt, ... ) { char bigbuffer[32000]; // big, but small enough to fit in PPC stack va_start( argptr,fmt ); - len = vsprintf( bigbuffer,fmt,argptr ); + len = vsnprintf( bigbuffer, sizeof( bigbuffer ), fmt, argptr ); va_end( argptr ); if ( len < 0 ) { Com_Error( ERR_FATAL, "Com_sprintf: failed to write bigbuffer" ); @@ -729,7 +729,7 @@ char * QDECL va( const char *format, ... ) { index++; va_start( argptr, format ); - vsprintf( buf, format,argptr ); + vsnprintf( buf, sizeof( string[index & 1] ), format, argptr ); va_end( argptr ); return buf; @@ -932,7 +932,7 @@ qboolean Info_Validate( const char *s ) { Changes or adds a key/value pair ================== */ -void Info_SetValueForKey( char *s, const char *key, const char *value ) { +void Info_SetValueForKey( char *s, const char *key, const char *value, size_t length ) { char newi[MAX_INFO_STRING]; if ( strlen( s ) >= MAX_INFO_STRING ) { @@ -966,7 +966,7 @@ void Info_SetValueForKey( char *s, const char *key, const char *value ) { return; } - strcat( s, newi ); + Q_strcat( s, length, newi ); } //==================================================================== diff --git a/libs/splines/q_shared.h b/libs/splines/q_shared.h index 9805fa8e..1854f8c1 100644 --- a/libs/splines/q_shared.h +++ b/libs/splines/q_shared.h @@ -771,7 +771,7 @@ int Com_IndexForGrowListElement( const growList_t *list, const void *ele // char *Info_ValueForKey( const char *s, const char *key ); void Info_RemoveKey( char *s, const char *key ); -void Info_SetValueForKey( char *s, const char *key, const char *value ); +void Info_SetValueForKey( char *s, const char *key, const char *value, size_t length ); qboolean Info_Validate( const char *s ); void Info_NextPair( const char *( *s ), char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] ); diff --git a/libs/splines/splines.cpp b/libs/splines/splines.cpp index 2d176550..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 ) { - memset( buff, 0, sizeof( buff ) ); - strcpy( buff, events[i]->getParam() ); + 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,7 +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 ) ); - strcpy( buff, events[i]->getParam() ); + 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/libs/splines/util_str.cpp b/libs/splines/util_str.cpp index 52a01a36..36799476 100644 --- a/libs/splines/util_str.cpp +++ b/libs/splines/util_str.cpp @@ -260,7 +260,7 @@ idStr operator+ const idStr& a, const float b ){ - char text[ 20 ]; + char text[ 64 ]; idStr result( a ); @@ -304,7 +304,7 @@ idStr& idStr::operator+= ( const float a ){ - char text[ 20 ]; + char text[ 64 ]; sprintf( text, "%f", a ); append( text ); @@ -371,6 +371,7 @@ void idStr::EnsureDataWritable EnsureAlloced( len + 1, false ); strncpy( m_data->data, olddata->data, len + 1 ); + m_data->data[len] = 0; m_data->len = len; olddata->DelRef(); @@ -447,12 +448,13 @@ void idStr::snprintf va_list argptr; va_start( argptr,fmt ); - len = vsprintf( buffer,fmt,argptr ); + len = vsnprintf( buffer, sizeof( buffer ), fmt, argptr ); va_end( argptr ); assert( len < size ); strncpy( dst, buffer, size - 1 ); + dst[size - 1] = NULL; } #ifdef _WIN32 diff --git a/libs/str.h b/libs/str.h index 0ee38f81..810c74e6 100644 --- a/libs/str.h +++ b/libs/str.h @@ -52,6 +52,15 @@ #define strcasecmp strcmpi #endif +#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); if ((_len) > 0) (_dst)[(_len) - 1] = 0; } while( 0 ) +#endif + + // NOTE TTimo __StrDup was initially implemented in pakstuff.cpp // causing a bunch of issues for broader targets that use Str.h (such as plugins and modules) // Q_StrDup should be used now, using a #define __StrDup for easy transition diff --git a/plugins/eclassfgd/plugin.cpp b/plugins/eclassfgd/plugin.cpp index 13089949..7d8f34b2 100644 --- a/plugins/eclassfgd/plugin.cpp +++ b/plugins/eclassfgd/plugin.cpp @@ -244,13 +244,13 @@ char *strlower( char *start ){ return start; } -char *addstr( char *dest,const char *source ){ +char *addstr( char *dest, const char *source ){ if ( dest ) { char *ptr; int len = strlen( dest ); ptr = (char *) malloc( len + strlen( source ) + 1 ); - strcpy( ptr,dest ); - strcpy( ptr + len,source ); + strcpy( ptr, dest ); + strcpy( ptr + len, source ); free( dest ); dest = ptr; } @@ -366,7 +366,7 @@ class_t *Find_Class( GSList *l,char *classname, class_t *ignore ){ Note: this is somewhat recursive, as a class can require a class that requires a class and so on.. */ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ - char color[128]; + char color[256]; // We allocate 16k here, but only the memory actually used is kept allocated. // this is just used for building the final comments string. @@ -382,8 +382,8 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ //represent the final values. if ( bc->description ) { - sprintf( newcomments,"%s\n",bc->description ); - e->comments = addstr( e->comments,newcomments ); + snprintf( newcomments, sizeof( newcomments ), "%s\n", bc->description ); + e->comments = addstr( e->comments, newcomments ); newcomments[0] = 0; // so we don't add them twice. } @@ -420,8 +420,8 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ // SIZE if ( bc->gotsize ) { e->fixedsize = true; - memcpy( e->mins,bc->boundingbox[0],sizeof( vec3_t ) ); - memcpy( e->maxs,bc->boundingbox[1],sizeof( vec3_t ) ); + memcpy( e->mins, bc->boundingbox[0], sizeof( vec3_t ) ); + memcpy( e->maxs, bc->boundingbox[1], sizeof( vec3_t ) ); } /* // Hydra: apparently, this would be bad. @@ -449,8 +449,8 @@ 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] ); + memcpy( e->color, bc->color, sizeof( vec3_t ) ); + snprintf( color, sizeof( color ), "(%f %f %f)", e->color[0], e->color[1], e->color[2] ); e->texdef.SetName( color ); } @@ -463,18 +463,22 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ if ( opt->optiontype != OPTION_FLAGS ) { // add some info to the comments. if ( opt->optioninfo ) { - sprintf( newcomments + strlen( newcomments ),"%s '%s' %s%s\n", - opt->epairname, - opt->optioninfo ? opt->optioninfo : "", - opt->optiondefault ? ", Default: " : "", - opt->optiondefault ? opt->optiondefault : "" ); + snprintf( newcomments + strlen( newcomments ), + sizeof( newcomments ) - strlen( newcomments ), + "%s '%s' %s%s\n", + opt->epairname, + opt->optioninfo ? opt->optioninfo : "", + opt->optiondefault ? ", Default: " : "", + opt->optiondefault ? opt->optiondefault : "" ); } else { - sprintf( newcomments + strlen( newcomments ),"%s %s%s\n", - opt->epairname, - opt->optiondefault ? ", Default: " : "", - opt->optiondefault ? opt->optiondefault : "" ); + snprintf( newcomments + strlen( newcomments ), + sizeof( newcomments ) - strlen( newcomments ), + "%s %s%s\n", + opt->epairname, + opt->optiondefault ? ", Default: " : "", + opt->optiondefault ? opt->optiondefault : "" ); } } @@ -490,7 +494,7 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ int index = getindex( choice->value ); index--; if ( index < MAX_FLAGS ) { - strcpy( e->flagnames[index],choice->name ); + Q_strncpyz( e->flagnames[index], choice->name, sizeof( e->flagnames[index] ) ); } else { @@ -499,11 +503,14 @@ void EClass_ImportFromClass( eclass_t *e, GSList *l_classes, class_t *bc ){ } break; case OPTION_CHOICES: - strcat( newcomments," Choices:\n" ); + strncat( newcomments, " Choices:\n", sizeof( newcomments ) ); for ( choicelst = opt->choices; choicelst != NULL; choicelst = choicelst->next ) { choice_t *choice = (choice_t*) choicelst->data; - sprintf( newcomments + strlen( newcomments )," %5d - %s\n",choice->value,choice->name ); + snprintf( newcomments + strlen( newcomments ), + sizeof( newcomments ) - strlen( newcomments ), + " %5d - %s\n", + choice->value,choice->name ); } break; } @@ -540,14 +547,14 @@ 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 ); } } // COMMENTS if ( newcomments[0] ) { - e->comments = addstr( e->comments,newcomments ); + e->comments = addstr( e->comments, newcomments ); } } @@ -589,12 +596,12 @@ void Create_EClasses( GSList *l_classes ){ if ( havespawnflags ) { char spawnline[80]; - e->comments = addstr( e->comments,"Spawnflags\n" ); + e->comments = addstr( e->comments, "Spawnflags\n" ); for ( i = 0 ; i < MAX_FLAGS ; i++ ) { if ( *e->flagnames[i] ) { - sprintf( spawnline," %d - %s\n", 1 << i, e->flagnames[i] ); - e->comments = addstr( e->comments,spawnline ); + snprintf( spawnline, sizeof( spawnline ), " %d - %s\n", 1 << i, e->flagnames[i] ); + e->comments = addstr( e->comments, spawnline ); } } } @@ -649,7 +656,7 @@ void Eclass_ScanFile( char *filename ){ } } while ( token[0] != '@' ); - strcpy( temp,token + 1 ); // skip the @ + Q_strncpyz( temp, token + 1, sizeof( temp ) );// skip the @ classtype = CLASS_NOCLASS; if ( !stricmp( temp,"BaseClass" ) ) { @@ -669,37 +676,37 @@ void Eclass_ScanFile( char *filename ){ while ( 1 ) { - GetTokenExtra( false,"(",false ); // option or = - strcpy( token_debug,token ); + GetTokenExtra( false, "(", false ); // option or = + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); - if ( !strcmp( token,"=" ) ) { + if ( !strcmp( token, "=" ) ) { UnGetToken(); break; } else { strlower( token ); - if ( !strcmp( token,"base" ) ) { - GetTokenExtra( false,"(",true ); // ( + if ( !strcmp( token, "base" ) ) { + GetTokenExtra( false, "(", true ); // ( - if ( !strcmp( token,"(" ) ) { - while ( GetTokenExtra( false,",)",false ) ) // option) or option, + if ( !strcmp( token, "(" ) ) { + while ( GetTokenExtra( false, ",)", false ) ) // option) or option, { newclass->l_baselist = g_slist_append( newclass->l_baselist, strdup( token ) ); - GetTokenExtra( false,",)",true ); // , or ) - if ( !strcmp( token,")" ) ) { + GetTokenExtra( false, ",)", true ); // , or ) + if ( !strcmp( token, ")" ) ) { break; } } } } - else if ( !strcmp( token,"size" ) ) { + else if ( !strcmp( token, "size" ) ) { // parse (w h d) or (x y z, x y z) - GetTokenExtra( false,"(",true ); // ( - if ( !strcmp( token,"(" ) ) { + GetTokenExtra( false, "(", true ); // ( + if ( !strcmp( token, "(" ) ) { int sizedone = false; float w,h,d; GetToken( false ); @@ -707,7 +714,7 @@ void Eclass_ScanFile( char *filename ){ GetToken( false ); h = atof( token ); GetToken( false ); // number) or number , - strcpy( temp,token ); + Q_strncpyz( temp, token, sizeof( temp ) ); len = strlen( temp ); if ( temp[len - 1] == ')' ) { sizedone = true; @@ -743,16 +750,16 @@ void Eclass_ScanFile( char *filename ){ GetToken(false); // ) newclass->boundingbox[1][2] = atof(temp); */ - GetTokenExtra( false,")",false ); // number + GetTokenExtra( false, ")", false ); // number newclass->boundingbox[1][2] = atof( token ); newclass->gotsize = true; - GetTokenExtra( false,")",true ); // ) + GetTokenExtra( false, ")", true ); // ) } } } - else if ( !strcmp( token,"color" ) ) { - GetTokenExtra( false,"(",true ); // ( - if ( !strcmp( token,"(" ) ) { + else if ( !strcmp( token, "color" ) ) { + GetTokenExtra( false, "(", true ); // ( + if ( !strcmp( token, "(" ) ) { // get the color values (0-255) and normalize them if required. GetToken( false ); newclass->color[0] = atof( token ); @@ -765,7 +772,7 @@ void Eclass_ScanFile( char *filename ){ newclass->color[1] /= 255; } GetToken( false ); - strcpy( temp,token ); + Q_strncpyz( temp, token, sizeof( temp ) ); len = strlen( temp ); if ( temp[len - 1] == ')' ) { temp[len - 1] = 0; @@ -777,22 +784,22 @@ void Eclass_ScanFile( char *filename ){ newclass->gotcolor = true; } } - else if ( !strcmp( token,"iconsprite" ) ) { - GetTokenExtra( false,"(",true ); // ( - if ( !strcmp( token,"(" ) ) { - GetTokenExtra( false,")",false ); // filename) + else if ( !strcmp( token, "iconsprite" ) ) { + GetTokenExtra( false, "(", true ); // ( + if ( !strcmp( token, "(" ) ) { + GetTokenExtra( false, ")", false ); // filename) // the model plugins will handle sprites too. // newclass->sprite = strdup(token); newclass->model = strdup( token ); - GetTokenExtra( false,")",true ); // ) + GetTokenExtra( false, ")", true ); // ) } } - else if ( !strcmp( token,"model" ) ) { - GetTokenExtra( false,"(",true ); // ( - if ( !strcmp( token,"(" ) ) { - GetTokenExtra( false,")",false ); // filename) + else if ( !strcmp( token, "model" ) ) { + GetTokenExtra( false, "(", true ); // ( + if ( !strcmp( token, "(" ) ) { + GetTokenExtra( false, ")", false ); // filename) newclass->model = strdup( token ); - GetTokenExtra( false,")",true ); // ) + GetTokenExtra( false, ")", true ); // ) } } else @@ -805,8 +812,8 @@ void Eclass_ScanFile( char *filename ){ } GetToken( false ); // = - strcpy( token_debug,token ); - if ( !strcmp( token,"=" ) ) { + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); + if ( !strcmp( token, "=" ) ) { GetToken( false ); newclass->classname = strdup( token ); } @@ -814,7 +821,7 @@ void Eclass_ScanFile( char *filename ){ // Get the description if ( newclass->classtype != CLASS_BASECLASS ) { GetToken( false ); - if ( !strcmp( token,":" ) ) { + if ( !strcmp( token, ":" ) ) { GetToken( false ); newclass->description = strdup( token ); } @@ -840,7 +847,8 @@ void Eclass_ScanFile( char *filename ){ } // parse the data and build the option_t - strcpy( temp,token ); + Q_strncpyz( temp, token, sizeof( temp ) ); + len = strlen( temp ); char *ptr = strchr( temp,'(' ); @@ -884,7 +892,7 @@ void Eclass_ScanFile( char *filename ){ break; } GetToken( false ); // : - strcpy( token_debug,token ); + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); if ( ( token[0] == ':' ) && ( strlen( token ) > 1 ) ) { newoption->optioninfo = strdup( token + 1 ); } @@ -909,18 +917,18 @@ void Eclass_ScanFile( char *filename ){ break; case OPTION_CHOICES: - GetTokenExtra( false,":",true ); // : or :"something like this" (bah!) - strcpy( token_debug,token ); + GetTokenExtra( false, ":", true ); // : or :"something like this" (bah!) + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); if ( ( token[0] == ':' ) && ( strlen( token ) > 1 ) ) { if ( token[1] == '\"' ) { - strcpy( temp,token + 2 ); + Q_strncpyz( temp, token + 2, sizeof( temp ) ); while ( 1 ) { if ( !GetToken( false ) ) { break; } - strcat( temp," " ); - strcat( temp,token ); + strncat( temp, " ", sizeof( temp ) ); + strncat( temp, token, sizeof( temp ) ); len = strlen( temp ); if ( temp[len - 1] == '\"' ) { temp[len - 1] = 0; @@ -936,7 +944,7 @@ void Eclass_ScanFile( char *filename ){ newoption->optioninfo = strdup( token ); } GetToken( false ); // : or = - strcpy( token_debug,token ); + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); if ( !strcmp( token,":" ) ) { GetToken( false ); newoption->optiondefault = strdup( token ); @@ -948,13 +956,13 @@ void Eclass_ScanFile( char *filename ){ // And Follow on... case OPTION_FLAGS: GetToken( false ); // : or = - strcpy( token_debug,token ); + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); if ( strcmp( token,"=" ) ) { // missing ? break; } GetToken( true ); // [ - strcpy( token_debug,token ); + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); if ( strcmp( token,"[" ) ) { // missing ? break; } @@ -962,13 +970,13 @@ void Eclass_ScanFile( char *filename ){ choice_t *newchoice; while ( 1 ) { - GetTokenExtra( true,":",true ); // "]" or "number", or "number:" - strcpy( token_debug,token ); - if ( !strcmp( token,"]" ) ) { // no more ? + GetTokenExtra( true, ":", true ); // "]" or "number", or "number:" + Q_strncpyz( token_debug, token, sizeof( token_debug ) ); + if ( !strcmp( token, "]" ) ) { // no more ? optioncomplete = true; break; } - strcpy( temp,token ); + Q_strncpyz( temp, token, sizeof( temp ) ); len = strlen( temp ); if ( temp[len - 1] == ':' ) { temp[len - 1] = 0; @@ -976,7 +984,7 @@ void Eclass_ScanFile( char *filename ){ else { GetToken( false ); // : - if ( strcmp( token,":" ) ) { // missing ? + if ( strcmp( token, ":" ) ) { // missing ? break; } } @@ -1061,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/imagem8/m8.cpp b/plugins/imagem8/m8.cpp index 4bf1f118..bb3d131a 100644 --- a/plugins/imagem8/m8.cpp +++ b/plugins/imagem8/m8.cpp @@ -35,17 +35,17 @@ void LoadM8( const char *name, unsigned char **pic, int *width, int *height ){ unsigned char *palette_ent, *buf_temp; unsigned char *buffer, *m8_file_buffer; - strcpy( text_buf, name ); + Q_strncpyz( text_buf, name, sizeof( text_buf ) ); text_dot_pos = strchr( text_buf, '.' ); if ( text_dot_pos ) { *text_dot_pos = 0; } // Fix for .pcx.m8 extention - strcat( text_buf, ".pcx.m8" ); + strncat( text_buf, ".pcx.m8", sizeof( text_buf ) ); // open file if ( ( length = vfsLoadFile( (char *) text_buf, (void **) &m8_file_buffer, 0 ) ) == (unsigned int) -1 ) { - strcpy( text_buf, name ); + Q_strncpyz( text_buf, name, sizeof( text_buf ) ); for ( i = ( strlen( text_buf ) - 1 ); i > 0; i-- ) { if ( text_buf[i] == '.' ) { @@ -53,7 +53,7 @@ void LoadM8( const char *name, unsigned char **pic, int *width, int *height ){ break; } } - strcat( text_buf, ".m8" ); + strncat( text_buf, ".m8", sizeof( text_buf ) ); if ( ( length = vfsLoadFile( (char *) text_buf, (void **) &m8_file_buffer, 0 ) ) == (unsigned int) -1 ) { Sys_Printf( "Unable to open file %s\n",name ); return; diff --git a/plugins/map/parse.cpp b/plugins/map/parse.cpp index 4305979a..744499ef 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, strlen( token ) + 10 - 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/xmlparse.cpp b/plugins/mapxml/xmlparse.cpp index 0de0a98b..3445f6f5 100644 --- a/plugins/mapxml/xmlparse.cpp +++ b/plugins/mapxml/xmlparse.cpp @@ -218,7 +218,7 @@ void HandleXMLError( void* ctxt, const char* text, ... ){ static char buf[32768]; va_start( argptr,text ); - vsprintf( buf, text, argptr ); + vsnprintf( buf, sizeof( buf ), text, argptr ); Sys_FPrintf( SYS_ERR, "XML %s\n", buf ); va_end( argptr ); } diff --git a/plugins/mapxml/xmlwrite.cpp b/plugins/mapxml/xmlwrite.cpp index 10052ee2..5ba6177d 100644 --- a/plugins/mapxml/xmlwrite.cpp +++ b/plugins/mapxml/xmlwrite.cpp @@ -40,15 +40,15 @@ char *str_append_token( char *str1, const char *str2 ){ return str; } -void str_from_float( char *buf, float f ){ +void str_from_float( char *buf, float f, size_t length ){ if ( f == (int)f ) { - sprintf( buf, "%i", (int)f ); + snprintf( buf, length, "%i", (int)f ); } - else{ sprintf( buf, "%f", f ); } + else{ snprintf( buf, length, "%f", f ); } } void Patch_XMLWrite( patchMesh_t *pPatch, xmlNodePtr surface ){ - char buf[16]; + char buf[64]; char *str; int i, j; xmlNodePtr node; @@ -62,29 +62,29 @@ void Patch_XMLWrite( patchMesh_t *pPatch, xmlNodePtr surface ){ { for ( j = 0; j < pPatch->height; j++ ) { - str_from_float( buf, pPatch->ctrl[i][j].xyz[0] ); + str_from_float( buf, pPatch->ctrl[i][j].xyz[0], sizeof( buf ) ); str = str_append_token( str, buf ); - str_from_float( buf, pPatch->ctrl[i][j].xyz[1] ); + str_from_float( buf, pPatch->ctrl[i][j].xyz[1], sizeof( buf ) ); str = str_append_token( str, buf ); - str_from_float( buf, pPatch->ctrl[i][j].xyz[2] ); + str_from_float( buf, pPatch->ctrl[i][j].xyz[2], sizeof( buf ) ); str = str_append_token( str, buf ); - str_from_float( buf, pPatch->ctrl[i][j].st[0] ); + str_from_float( buf, pPatch->ctrl[i][j].st[0], sizeof( buf ) ); str = str_append_token( str, buf ); - str_from_float( buf, pPatch->ctrl[i][j].st[1] ); + str_from_float( buf, pPatch->ctrl[i][j].st[1], sizeof( buf ) ); str = str_append_token( str, buf ); } } 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 ); } void Face_XMLWrite( face_t *face, xmlNodePtr surface, bool bAlternateTexdef = false ){ - char buf[16]; + char buf[64]; xmlNodePtr node; int i, j; char *str; @@ -98,7 +98,7 @@ void Face_XMLWrite( face_t *face, xmlNodePtr surface, bool bAlternateTexdef = fa { for ( j = 0 ; j < 3 ; j++ ) { - str_from_float( buf, face->planepts[i][j] ); + str_from_float( buf, face->planepts[i][j], sizeof( buf ) ); str = str_append_token( str, 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 ); @@ -130,7 +130,7 @@ void Face_XMLWrite( face_t *face, xmlNodePtr surface, bool bAlternateTexdef = fa { for ( j = 0 ; j < 3 ; j++ ) { - str_from_float( buf, face->brushprimit_texdef.coords[i][j] ); + str_from_float( buf, face->brushprimit_texdef.coords[i][j], sizeof( buf ) ); str = str_append_token( str, buf ); } } @@ -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 dd3e305e..ba29193b 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 ) ); } } @@ -178,15 +178,15 @@ extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool else if ( !strcmp( p, "About" ) ) { const picoModule_t** modules = PicoModuleList( NULL ); char about_buf[1024]; - strncpy( about_buf, PLUGIN_ABOUT, sizeof( about_buf ) - 1 ); + Q_strncpyz( about_buf, PLUGIN_ABOUT, sizeof( about_buf ) ); while ( *modules != NULL ) { const picoModule_t* module = *modules++; - strncat( about_buf, module->displayName, sizeof( about_buf ) - 1 ); - strncat( about_buf, " (", sizeof( about_buf ) - 1 ); - strncat( about_buf, module->defaultExts[0], sizeof( about_buf ) - 1 ); - strncat( about_buf, ")\n\t", sizeof( about_buf ) - 1 ); - strncat( about_buf, module->copyright, sizeof( about_buf ) - 1 ); - strncat( about_buf, "\n", sizeof( about_buf ) - 1 ); + strncat( about_buf, module->displayName, sizeof( about_buf ) ); + strncat( about_buf, " (", sizeof( about_buf ) ); + strncat( about_buf, module->defaultExts[0], sizeof( about_buf ) ); + strncat( about_buf, ")\n\t", sizeof( about_buf ) ); + strncat( about_buf, module->copyright, sizeof( about_buf ) ); + strncat( about_buf, "\n", sizeof( about_buf ) ); } g_FuncTable.m_pfnMessageBox( NULL, about_buf, "About", MB_OK, NULL ); } diff --git a/plugins/model/remap.cpp b/plugins/model/remap.cpp index 5e313222..65d0f934 100644 --- a/plugins/model/remap.cpp +++ b/plugins/model/remap.cpp @@ -164,7 +164,7 @@ void add_remap( const char *remap ){ else { pRemap = new remap_t; - strncpy( pRemap->m_remapbuff, remap, sizeof( pRemap->m_remapbuff ) ); + Q_strncpyz( pRemap->m_remapbuff, remap, sizeof( pRemap->m_remapbuff ) ); pRemap->m_remapbuff[ch - remap] = '\0'; diff --git a/plugins/shaders/shaders.cpp b/plugins/shaders/shaders.cpp index 792b2ad0..4e42e93f 100644 --- a/plugins/shaders/shaders.cpp +++ b/plugins/shaders/shaders.cpp @@ -71,7 +71,7 @@ const char *WINAPI QERApp_CleanTextureName( const char *name, bool bAddTexture = } #endif - strcpy( stdName, name ); + Q_strncpyz( stdName, name, sizeof( stdName ) ); g_FuncTable.m_pfnQE_ConvertDOSToUnixName( stdName, stdName ); if ( stdName[strlen( name ) - 4] == '.' ) { // strip extension @@ -80,8 +80,8 @@ const char *WINAPI QERApp_CleanTextureName( const char *name, bool bAddTexture = if ( bAddTexture ) { char aux[QER_MAX_NAMELEN]; - sprintf( aux, "textures/%s", stdName ); - strcpy( stdName, aux ); + snprintf( aux, sizeof( aux ), "textures/%s", stdName ); + Q_strncpyz( stdName, aux, sizeof( stdName ) ); } return stdName; } @@ -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 857db380..2c98b208 100644 --- a/plugins/surface/surfacedialog.cpp +++ b/plugins/surface/surfacedialog.cpp @@ -201,7 +201,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]; @@ -288,6 +288,7 @@ static void PopulateTextureComboList(){ texdef_to_face_t* temp_texdef_face_list; char blank[1]; GList *items = NULL; + GList *lst; int num_of_list_items = 0; blank[0] = 0; @@ -295,14 +296,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 { @@ -322,7 +323,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 ) ); } gtk_combo_set_popdown_strings( GTK_COMBO( texture_combo ), items ); @@ -1232,7 +1233,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, ' ' ) ) { @@ -1244,7 +1245,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 e2fa7a89..9c07708c 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]; @@ -260,14 +260,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 { @@ -287,7 +287,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 ) ); } gtk_combo_set_popdown_strings( GTK_COMBO( texture_combo ), items ); @@ -879,7 +879,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, ' ' ) ) { @@ -891,7 +891,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 e8ec68cf..eec56991 100644 --- a/plugins/surface_idtech2/surfaceflags.cpp +++ b/plugins/surface_idtech2/surfaceflags.cpp @@ -33,8 +33,7 @@ GtkWidget *notebook1; // 32 bit is the max #define MAX_BUTTONS 32 -#ifdef _WIN32 -// TTimo: THIS IS UGLY +#if defined(_MSC_VER) && _MSC_VER<1900 && !(defined snprintf) #define snprintf _snprintf #endif @@ -87,7 +86,7 @@ void set_surface_flags_button_state( texdef_to_face_t *texdef_face_list, bool b_ int diff_contents = 0; int diff_flags = 0; gboolean diff_value = FALSE; - char tex_buff[11]; + char tex_buff[16]; texdef_t* tmp_texdef; texdef_to_face_t* temp_texdef_face_list; int i; @@ -164,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 ); } @@ -302,7 +301,7 @@ GtkWidget* create_SurfaceFlagsFrame( GtkWidget* surfacedialog_widget ){ GtkWidget *label6; int i, x, y; const char *buttonLabel; - char buffer[8]; + char buffer[16]; frame1 = gtk_frame_new( _( "Flags" ) ); gtk_widget_show( frame1 ); @@ -334,7 +333,7 @@ GtkWidget* create_SurfaceFlagsFrame( GtkWidget* surfacedialog_widget ){ y++; } x = i % 4; - snprintf( buffer, sizeof( buffer ) - 1, "surf%i", i + 1 ); + snprintf( buffer, sizeof( buffer ), "surf%i", i + 1 ); buttonLabel = g_FuncTable.m_pfnReadProjectKey( buffer ); //Sys_Printf( "%s: %s\n", buffer, buttonLabel ); surface_buttons[i] = gtk_toggle_button_new_with_label( buttonLabel ); @@ -392,7 +391,7 @@ GtkWidget* create_SurfaceFlagsFrame( GtkWidget* surfacedialog_widget ){ y++; } x = i % 4; - snprintf( buffer, sizeof( buffer ) - 1, "cont%i", i + 1 ); + snprintf( buffer, sizeof( buffer ), "cont%i", i + 1 ); buttonLabel = g_FuncTable.m_pfnReadProjectKey( buffer ); content_buttons[i] = gtk_toggle_button_new_with_label( buttonLabel ); gtk_signal_connect( GTK_OBJECT( content_buttons[i] ), "toggled", GTK_SIGNAL_FUNC( on_content_button_toggled ), GINT_TO_POINTER( 1 << i ) ); diff --git a/plugins/vfspak/vfs.cpp b/plugins/vfspak/vfs.cpp index 1c72c79b..364a45e4 100644 --- a/plugins/vfspak/vfs.cpp +++ b/plugins/vfspak/vfs.cpp @@ -93,11 +93,11 @@ static bool g_bUsePak = true; // ============================================================================= // Static functions -static void vfsAddSlash( char *str ){ +static void vfsAddSlash( char *str, size_t length ){ int n = strlen( str ); if ( n > 0 ) { if ( str[n - 1] != '\\' && str[n - 1] != '/' ) { - strcat( str, "/" ); + strncat( str, "/", length ); } } } @@ -182,10 +182,10 @@ static GSList* vfsGetListInternal( const char *dir, const char *ext, bool direct dirname[0] = '\0'; if ( dir != NULL ) { - strcat( dirname, dir ); + strncat( dirname, dir, sizeof( dirname ) ); strlwr( dirname ); vfsFixDOSName( dirname ); - vfsAddSlash( dirname ); + vfsAddSlash( dirname, sizeof( dirname ) ); Sys_Printf( "vfs dirname_1: %s\n", dirname ); } //else @@ -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'; @@ -259,11 +259,11 @@ static GSList* vfsGetListInternal( const char *dir, const char *ext, bool direct for ( i = 0; i < g_numDirs; i++ ) { - strcpy( dirname, g_strDirs[i] ); - strcat( dirname, dir ); + Q_strncpyz( dirname, g_strDirs[i], sizeof( dirname ) ); + strncat( dirname, dir, sizeof( dirname ) ); strlwr( dirname ); vfsFixDOSName( dirname ); - vfsAddSlash( dirname ); + vfsAddSlash( dirname, sizeof( dirname ) ); diskdir = g_dir_open( dirname, 0, NULL ); @@ -279,7 +279,7 @@ static GSList* vfsGetListInternal( const char *dir, const char *ext, bool direct continue; } - sprintf( filename, "%s%s", dirname, name ); + snprintf( filename, sizeof( filename ), "%s%s", dirname, name ); stat( filename, &st ); Sys_Printf( "vfs FileName: %s\n", filename ); @@ -381,9 +381,9 @@ 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] ); + vfsAddSlash( g_strDirs[g_numDirs], sizeof( g_strDirs[g_numDirs] ) ); g_numDirs++; if ( g_bUsePak ) { @@ -417,9 +417,9 @@ void vfsInitDirectory( const char *path ){ while ( dirlist ) { GSList *cur = dirlist; - char* name = (char*)cur->data; + gchar* name = (gchar*)cur->data; - sprintf( filename, "%s/%s", path, name ); + snprintf( filename, sizeof( filename ), "%s/%s", path, name ); vfsInitPakFile( filename ); g_free( name ); @@ -471,7 +471,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 ); @@ -486,8 +486,8 @@ int vfsGetFileCount( const char *filename, int flag ){ for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, fixed ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, fixed, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { count++; } @@ -503,14 +503,14 @@ 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 ); for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, filename ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, filename, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { if ( count == index ) { long len; @@ -646,11 +646,11 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ } else { - strcpy( l_in,in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); } vfsCleanFileName( l_in ); #else - strcpy( l_in, in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); vfsCleanFileName( l_in ); #endif // ifdef WIN32 @@ -661,7 +661,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ for ( i = 0; i < g_numDirs; i++ ) { - strcpy( check,g_strDirs[i] ); + Q_strncpyz( check, g_strDirs[i], sizeof( check ) ); vfsCleanFileName( check ); #ifdef DBG_RLTPATH Sys_Printf( "Matching against %s\n", check ); @@ -669,7 +669,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ // 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; } @@ -701,7 +701,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 ); @@ -716,7 +716,7 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ lastptr = ptr + 1; if ( strcmp( lastptr, fixed ) == 0 ) { - strncpy( out,file->name,PATH_MAX ); + Q_strncpyz( out, file->name, sizeof( out ) ); return out; } } @@ -726,11 +726,11 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, in ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + 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++; @@ -762,7 +762,7 @@ char* vfsExtractRelativePath( const char *in ){ } } // this is the clean, not short version - strcpy( out, in ); + Q_strncpyz( out, in, sizeof( out ) ); vfsCleanFileName( out ); for ( i = 0; i <= count; i++ ) { diff --git a/plugins/vfspk3/vfs.cpp b/plugins/vfspk3/vfs.cpp index c556d0a5..df1549e8 100644 --- a/plugins/vfspk3/vfs.cpp +++ b/plugins/vfspk3/vfs.cpp @@ -86,11 +86,11 @@ static bool g_bUsePak = true; // ============================================================================= // Static functions -static void vfsAddSlash( char *str ){ +static void vfsAddSlash( char *str, size_t length ){ int n = strlen( str ); if ( n > 0 ) { if ( str[n - 1] != '\\' && str[n - 1] != '/' ) { - strcat( str, "/" ); + strncat( str, "/", length ); } } } @@ -174,10 +174,10 @@ 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 ); + vfsAddSlash( dirname, sizeof( dirname ) ); } else{ dirname[0] = '\0'; @@ -185,7 +185,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'; @@ -252,8 +252,8 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir for ( i = 0; i < g_numDirs; i++ ) { - strcpy( basedir, g_strDirs[i] ); - strcat( basedir, dirname ); + Q_strncpyz( basedir, g_strDirs[i], sizeof( basedir ) ); + strncat( basedir, dirname, sizeof( basedir ) ); diskdir = g_dir_open( basedir, 0, NULL ); @@ -269,7 +269,7 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir continue; } - sprintf( filename, "%s%s", basedir, name ); + snprintf( filename, sizeof( filename ), "%s%s", basedir, name ); stat( filename, &st ); if ( ( S_ISDIR( st.st_mode ) != 0 ) != directories ) { @@ -394,9 +394,9 @@ void vfsInitDirectory( const char *path ){ iGameMode = 0; } - 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] ); + vfsAddSlash( g_strDirs[g_numDirs], sizeof( g_strDirs[g_numDirs] ) ); g_numDirs++; if ( g_bUsePak ) { @@ -423,13 +423,13 @@ void vfsInitDirectory( const char *path ){ switch ( iGameMode ) { case 1: // SP - if ( strncmp( direntry,"sp_",3 ) == 0 ) { - memcpy( direntry,"zz",2 ); + if ( strncmp( direntry, "sp_", 3 ) == 0 ) { + memcpy( direntry, "zz", 2 ); } break; case 2: // MP - if ( strncmp( direntry,"mp_",3 ) == 0 ) { - memcpy( direntry,"zz",2 ); + if ( strncmp( direntry, "mp_", 3 ) == 0 ) { + memcpy( direntry, "zz", 2 ); } break; } @@ -451,28 +451,28 @@ void vfsInitDirectory( const char *path ){ switch ( iGameMode ) { case 1: // SP - if ( strncmp( name,"mp_",3 ) == 0 ) { + if ( strncmp( name, "mp_", 3 ) == 0 ) { g_free( name ); dirlist = g_slist_remove( cur, name ); continue; } - else if ( strncmp( name,"zz_",3 ) == 0 ) { - memcpy( name,"sp",2 ); + else if ( strncmp( name, "zz_", 3 ) == 0 ) { + memcpy( name, "sp", 2 ); } break; case 2: // MP - if ( strncmp( name,"sp_",3 ) == 0 ) { + if ( strncmp( name, "sp_", 3 ) == 0 ) { g_free( name ); dirlist = g_slist_remove( cur, name ); continue; } - else if ( strncmp( name,"zz_",3 ) == 0 ) { - memcpy( name,"mp",2 ); + else if ( strncmp( name, "zz_", 3 ) == 0 ) { + memcpy( name, "mp", 2 ); } break; } - sprintf( filename, "%s/%s", path, name ); + snprintf( filename, sizeof( filename ), "%s/%s", path, name ); vfsInitPakFile( filename ); g_free( name ); @@ -534,7 +534,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 ); @@ -552,8 +552,8 @@ int vfsGetFileCount( const char *filename, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, fixed ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, fixed, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { count++; } @@ -598,14 +598,14 @@ 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 ); for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, filename ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, filename, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { if ( count == index ) { return vfsLoadFullPathFile( tmp,bufferptr ); @@ -684,11 +684,11 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ } else { - strcpy( l_in,in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); } vfsCleanFileName( l_in ); #else - strcpy( l_in, in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); vfsCleanFileName( l_in ); #endif // ifdef WIN32 @@ -699,7 +699,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ for ( i = 0; i < g_numDirs; i++ ) { - strcpy( check,g_strDirs[i] ); + Q_strncpyz( check, g_strDirs[i], sizeof( check ) ); vfsCleanFileName( check ); #ifdef DBG_RLTPATH Sys_Printf( "Matching against %s\n", check ); @@ -707,7 +707,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ // 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; } @@ -747,7 +747,7 @@ char* vfsExtractRelativePath( const char *in ){ } } // this is the clean, not short version - strcpy( out, in ); + Q_strncpyz( out, in, sizeof( out ) ); vfsCleanFileName( out ); for ( i = 0; i <= count; i++ ) { @@ -788,7 +788,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 ); @@ -803,7 +803,7 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ lastptr = ptr + 1; if ( strcmp( lastptr, fixed ) == 0 ) { - strncpy( out,file->name,PATH_MAX ); + Q_strncpyz( out, file->name, sizeof( out ) ); return out; } } @@ -813,11 +813,11 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, in ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + 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/vfsqlpk3/vfs.cpp b/plugins/vfsqlpk3/vfs.cpp index 160c860b..fcaa17f3 100644 --- a/plugins/vfsqlpk3/vfs.cpp +++ b/plugins/vfsqlpk3/vfs.cpp @@ -85,11 +85,11 @@ static bool g_bUsePak = true; // ============================================================================= // Static functions -static void vfsAddSlash( char *str ){ +static void vfsAddSlash( char *str, size_t length ){ int n = strlen( str ); if ( n > 0 ) { if ( str[n - 1] != '\\' && str[n - 1] != '/' ) { - strcat( str, "/" ); + strncat( str, "/", length ); } } } @@ -172,10 +172,10 @@ 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 ); + vfsAddSlash( dirname, sizeof( dirname ) ); } else{ dirname[0] = '\0'; @@ -183,7 +183,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'; @@ -250,8 +250,8 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir for ( i = 0; i < g_numDirs; i++ ) { - strcpy( basedir, g_strDirs[i] ); - strcat( basedir, dirname ); + Q_strncpyz( basedir, g_strDirs[i], sizeof( basedir ) ); + strncat( basedir, dirname, sizeof( basedir ) ); diskdir = g_dir_open( basedir, 0, NULL ); @@ -267,7 +267,7 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir continue; } - sprintf( filename, "%s%s", basedir, name ); + snprintf( filename, sizeof( filename ), "%s%s", basedir, name ); stat( filename, &st ); if ( ( S_ISDIR( st.st_mode ) != 0 ) != directories ) { @@ -392,9 +392,9 @@ void vfsInitDirectory( const char *path ){ iGameMode = 0; } - 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] ); + vfsAddSlash( g_strDirs[g_numDirs], sizeof( g_strDirs[g_numDirs] ) ); g_numDirs++; if ( g_bUsePak ) { @@ -470,7 +470,7 @@ void vfsInitDirectory( const char *path ){ break; } - sprintf( filename, "%s/%s", path, name ); + snprintf( filename, sizeof( filename ), "%s/%s", path, name ); vfsInitPakFile( filename ); g_free( name ); @@ -532,7 +532,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 ); @@ -550,8 +550,8 @@ int vfsGetFileCount( const char *filename, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, fixed ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, fixed, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { count++; } @@ -596,14 +596,14 @@ 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 ); for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, filename ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, filename, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { if ( count == index ) { return vfsLoadFullPathFile( tmp,bufferptr ); @@ -682,11 +682,11 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ } else { - strcpy( l_in,in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); } vfsCleanFileName( l_in ); #else - strcpy( l_in, in ); + Q_strncpyz( l_in, in, sizeof( l_in ) ); vfsCleanFileName( l_in ); #endif // ifdef WIN32 @@ -697,7 +697,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ for ( i = 0; i < g_numDirs; i++ ) { - strcpy( check,g_strDirs[i] ); + Q_strncpyz( check, g_strDirs[i], sizeof( check ) ); vfsCleanFileName( check ); #ifdef DBG_RLTPATH Sys_Printf( "Matching against %s\n", check ); @@ -705,7 +705,7 @@ char* vfsExtractRelativePath_short( const char *in, bool shorten ){ // 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; } @@ -745,7 +745,7 @@ char* vfsExtractRelativePath( const char *in ){ } } // this is the clean, not short version - strcpy( out, in ); + Q_strncpyz( out, in, sizeof( out ) ); vfsCleanFileName( out ); for ( i = 0; i <= count; i++ ) { @@ -786,7 +786,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 ); @@ -801,7 +801,7 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ lastptr = ptr + 1; if ( strcmp( lastptr, fixed ) == 0 ) { - strncpy( out,file->name,PATH_MAX ); + Q_strncpyz( out, file->name, sizeof( out ) ); return out; } } @@ -811,11 +811,11 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, in ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + 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.cpp b/plugins/vfswad/vfs.cpp index e9a17be3..6afa6289 100644 --- a/plugins/vfswad/vfs.cpp +++ b/plugins/vfswad/vfs.cpp @@ -85,11 +85,11 @@ static int g_numDirs; // ============================================================================= // Static functions -static void vfsAddSlash( char *str ){ +static void vfsAddSlash( char *str, size_t length ){ int n = strlen( str ); if ( n > 0 ) { if ( str[n - 1] != '\\' && str[n - 1] != '/' ) { - strcat( str, "/" ); + strncat( str, "/", length ); } } } @@ -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 ); @@ -190,10 +190,10 @@ static void vfsInitPakFile( const char *filename ){ // texturenames in wad files don't have an extensions or paths, so we must add them! if ( wf->lpLump->type == WAD2_TYPE_MIP ) { - sprintf( filename_inwadfixed,"textures/%s/%s.mip",wadname,filename_inwad ); + snprintf( filename_inwadfixed, sizeof( filename_inwadfixed ), "textures/%s/%s.mip", wadname,filename_inwad ); } else { - sprintf( filename_inwadfixed,"textures/%s/%s.hlw",wadname,filename_inwad ); + snprintf( filename_inwadfixed, sizeof( filename_inwadfixed ), "textures/%s/%s.hlw", wadname,filename_inwad ); } //g_FuncTable.m_pfnSysFPrintf(SYS_WRN, " scanned %s\\%s\n", filename,filename_inwad); @@ -221,10 +221,10 @@ 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 ); + vfsAddSlash( dirname, sizeof( dirname ) ); } else{ dirname[0] = '\0'; @@ -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'; @@ -299,8 +299,8 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir for ( i = 0; i < g_numDirs; i++ ) { - strcpy( basedir, g_strDirs[i] ); - strcat( basedir, dirname ); + Q_strncpyz( basedir, g_strDirs[i], sizeof( basedir ) ); + strncat( basedir, dirname, sizeof( basedir ) ); GDir* dir = g_dir_open( basedir, 0, NULL ); @@ -316,7 +316,7 @@ static GSList* vfsGetListInternal( const char *refdir, const char *ext, bool dir continue; } - sprintf( filename, "%s%s", basedir, name ); + snprintf( filename, sizeof( filename ), "%s%s", basedir, name ); stat( filename, &st ); if ( ( S_ISDIR( st.st_mode ) != 0 ) != directories ) { @@ -366,9 +366,9 @@ 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] ); + vfsAddSlash( g_strDirs[g_numDirs], sizeof( g_strDirs[g_numDirs] ) ); g_numDirs++; // if (g_PrefsDlg.m_bPAK) @@ -389,7 +389,7 @@ void vfsInitDirectory( const char *path ){ continue; } - sprintf( filename, "%s/%s", path, name ); + snprintf( filename, sizeof( filename ), "%s/%s", path, name ); vfsInitPakFile( filename ); } g_dir_close( dir ); @@ -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 ); @@ -468,8 +468,8 @@ int vfsGetFileCount( const char *filename, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, fixed ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, fixed, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { count++; } @@ -514,14 +514,14 @@ 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 ); for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, filename ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, filename, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { if ( count == index ) { return vfsLoadFullPathFile( tmp,bufferptr ); @@ -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 ); @@ -709,7 +709,7 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ lastptr = ptr + 1; if ( strcmp( lastptr, fixed ) == 0 ) { - strncpy( out,file->name,PATH_MAX ); + Q_strncpyz( out, file->name, sizeof( out ) ); return out; } } @@ -719,11 +719,11 @@ char* vfsGetFullPath( const char *in, int index, int flag ){ if ( !flag || ( flag & VFS_SEARCH_DIR ) ) { for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, in ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + 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 2d07acad..b0ba7e76 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; @@ -1536,13 +1536,13 @@ const char* Brush_GetKeyValue( brush_t *b, const char *pKey ){ temporary stuff, detect potential problems when saving the texture name ================= */ -void CheckName( face_t *fa, char *pname ){ +void CheckName( face_t *fa, char *pname, size_t length ){ if ( !strlen( fa->texdef.GetName() ) ) { #ifdef _DEBUG Sys_FPrintf( SYS_WRN, "WARNING: unexpected texdef.name is empty in Brush.cpp CheckName\n" ); #endif fa->texdef.SetName( SHADER_NOT_FOUND ); - strcpy( pname, SHADER_NOT_FOUND ); + Q_strncpyz( pname, SHADER_NOT_FOUND, length ); return; } @@ -1550,11 +1550,11 @@ void CheckName( face_t *fa, char *pname ){ if ( strchr( fa->texdef.GetName(), ' ' ) ) { char Msg1[1024]; - sprintf( Msg1, "Can't save texture with spaces in name. Rename %s\nNOTE: This message may popup several times .. once for each buggy face detected.", fa->texdef.GetName() ); + snprintf( Msg1, sizeof( Msg1 ), "Can't save texture with spaces in name. Rename %s\nNOTE: This message may popup several times .. once for each buggy face detected.", fa->texdef.GetName() ); Sys_Printf( "%s\n", Msg1 ); gtk_MessageBox( g_pParentWnd->m_pWidget, Msg1, "Error saving map", MB_OK ); - strcpy( pname, SHADER_NOT_FOUND ); + Q_strncpyz( pname, SHADER_NOT_FOUND, length ); return; } @@ -1566,10 +1566,10 @@ void CheckName( face_t *fa, char *pname ){ gtk_MessageBox( g_pParentWnd->m_pWidget, text, "Error saving map", MB_OK ); // need to cleanup this dead face name or we may loop endlessly fa->texdef.SetName( SHADER_NOT_FOUND ); - strcpy( pname, SHADER_NOT_FOUND ); + Q_strncpyz( pname, SHADER_NOT_FOUND, length ); return; } - strcpy( pname, fa->texdef.GetName() + 9 ); // remove "textures/" + Q_strncpyz( pname, fa->texdef.GetName() + 9, length ); // remove "textures/" } /* @@ -3401,7 +3401,7 @@ void Brush_Move( brush_t *b, const vec3_t move, bool bSnap ){ if ( b->owner->eclass->fixedsize ) { char text[64]; VectorAdd( b->owner->origin, move, b->owner->origin ); - 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 ); //VectorAdd(b->maxs, b->mins, b->owner->origin); diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index e95f5b67..327e875c 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -119,7 +119,7 @@ void Dialog::AddModalButton( GtkWidget *widget, int ret ) { void Dialog::UpdateData( bool retrieve ){ DLG_DATA *data; GSList *lst; - char buf[32]; + char buf[64]; if ( retrieve ) { for ( lst = m_pDataList; lst != NULL; lst = g_slist_next( lst ) ) @@ -221,11 +221,11 @@ void Dialog::UpdateData( bool retrieve ){ gtk_entry_set_text( GTK_ENTRY( data->object ), txt ); } break; case DLG_ENTRY_FLOAT: - sprintf( buf, "%g", ( *(float*)data->buffer ) ); + snprintf( buf, sizeof( buf ), "%g", ( *(float*)data->buffer ) ); 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 3840d578..37203239 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 4b2e1fbc..d89a8e6c 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 ) { @@ -269,7 +269,7 @@ void EClass_InitForFileList( GSList *pFiles, _EClassTable *pTable ){ // this allows to override baseq3/scripts/entities.def for instance char relPath[PATH_MAX]; strcpy( relPath, "scripts/" ); - strcat( relPath, (char*)pFile->data ); + strncat( relPath, (char*)pFile->data, sizeof( relPath ) ); if ( !vfsGetFullPath( relPath, 0, 0 ) ) { Sys_FPrintf( SYS_ERR, "Failed to find the full path for '%s' in the VFS\n", relPath ); } @@ -286,7 +286,7 @@ void EClass_InitForFileList( GSList *pFiles, _EClassTable *pTable ){ */ eclass_t * EClass_Create( const char *name, float col1, float col2, float col3, const vec3_t *mins, const vec3_t *maxs, const char *comments ){ eclass_t *e; - char color[128]; + char color[256]; e = (eclass_t*)malloc( sizeof( *e ) ); memset( e, 0, sizeof( *e ) ); @@ -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 ? @@ -313,13 +313,13 @@ eclass_t * EClass_Create( const char *name, float col1, float col2, float col3, // b) no entity definition files were found // c) no entity definition file contained an entry for worldspawn. - if ( stricmp( name,"worldspawn" ) != 0 ) { + if ( stricmp( name, "worldspawn" ) != 0 ) { e->fixedsize = true; } // copy the sizes.. - memcpy( e->mins,mins,sizeof( vec3_t ) ); - memcpy( e->maxs,maxs,sizeof( vec3_t ) ); + memcpy( e->mins, mins, sizeof( vec3_t ) ); + memcpy( e->maxs, maxs, sizeof( vec3_t ) ); } if ( comments ) { @@ -404,7 +404,7 @@ void Eclass_Init(){ // this allows to override baseq3/scripts/entities.def for instance char relPath[PATH_MAX]; strcpy( relPath, "scripts/" ); - strcat( relPath, (char*)pFile->data ); + strncat( relPath, (char*)pFile->data, sizeof( relPath ) ); char *fullpath = vfsGetFullPath( relPath, 0, 0 ); if ( !fullpath ) { Sys_FPrintf( SYS_ERR, "Failed to find the full path for \"%s\" in the VFS\n", relPath ); diff --git a/radiant/eclass_def.cpp b/radiant/eclass_def.cpp index d2dcb987..052d7cc4 100644 --- a/radiant/eclass_def.cpp +++ b/radiant/eclass_def.cpp @@ -113,8 +113,7 @@ void setSpecialLoad( eclass_t *e, const char* pWhat, char*& p ){ if ( where ) { int len = ( where - pText ); p = new char[len + 1]; - strncpy( p,pText,len ); - p[len] = 0; // just to make sure, as most implementations of strncpy don't null terminate + Q_strncpyz( p, pText, len + 1 ); } else{ p = strdup( pText ); @@ -129,7 +128,7 @@ eclass_t *Eclass_InitFromText( char *text ){ int r, i; char parms[256], *p; eclass_t *e; - char color[128]; + char color[256]; e = (eclass_t*)malloc( sizeof( *e ) ); memset( e, 0, sizeof( *e ) ); @@ -147,7 +146,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 ); @@ -204,7 +203,12 @@ eclass_t *Eclass_InitFromText( char *text ){ if ( !p ) { break; } - strcpy( e->flagnames[i], Get_COM_Token() ); + Q_strncpyz( e->flagnames[i], Get_COM_Token(), sizeof( e->flagnames[i] ) ); + + if( strlen( Get_COM_Token() ) > sizeof( e->flagnames[i] ) - 1 ) + { + Syn_Printf( "Warning: spawnflag/parm/flagname too long for Eclass %s: %s\n", e->name, e->flagnames[i] ); + } } // find the length until close comment @@ -289,7 +293,7 @@ void Eclass_ScanFile( char *filename ){ eclass_found = false; for ( i = 0 ; i < size ; i++ ) { - if ( !strncmp( data + i, "/*QUAKED",8 ) ) { + if ( !strncmp( data + i, "/*QUAKED", 8 ) ) { e = Eclass_InitFromText( data + i ); if ( e ) { Eclass_InsertAlphabetized( e ); diff --git a/radiant/error.cpp b/radiant/error.cpp index 4044cb74..b0298599 100644 --- a/radiant/error.cpp +++ b/radiant/error.cpp @@ -45,16 +45,16 @@ void Error( const char *error, ... ){ char text[4096]; va_start( argptr,error ); - vsprintf( text, error,argptr ); + vsnprintf( text, sizeof( text ), error, argptr ); va_end( argptr ); - strcat( text, "\n" ); + strncat( text, "\n", sizeof( text ) ); #if defined ( __linux__ ) || defined ( __APPLE__ ) if ( errno != 0 ) { - strcat( text, "errno: " ); - strcat( text, strerror( errno ) ); - strcat( text, "\n" ); + strncat( text, "errno: ", sizeof( text ) ); + strncat( text, strerror( errno ), sizeof( text ) ); + strncat( text, "\n", sizeof( text ) ); } #endif @@ -72,7 +72,7 @@ void Error( const char *error, ... ){ 0, NULL ); - strcat( text, "GetLastError: " ); + strncat( text, "GetLastError: ", sizeof( text ) ); /* Gtk will only crunch 0<=char<=127 this is a bit hackish, but I didn't find useful functions in win32 API for this @@ -90,7 +90,7 @@ void Error( const char *error, ... ){ } next = CharNext( scan ); } while ( next != scan ); - strcat( text, "\n" ); + strncat( text, "\n", sizeof( text ) ); LocalFree( lpMsgBuf ); } #endif @@ -103,14 +103,14 @@ void Error( const char *error, ... ){ GLenum iGLError = qglGetError(); if ( iGLError != GL_NO_ERROR ) { // use our own gluErrorString - strcat( text, "qgluErrorString: " ); - strcat( text, (char*)qgluErrorString( iGLError ) ); - strcat( text, "\n" ); + strncat( text, "qgluErrorString: ", sizeof( text ) ); + strncat( text, (char*)qgluErrorString( iGLError ), sizeof( text ) ); + strncat( text, "\n", sizeof( text ) ); } } - strcat( text, "An unrecoverable error has occured.\n" - "Would you like to edit Preferences before exiting Radiant?" ); + strncat( text, "An unrecoverable error has occured.\n" + "Would you like to edit Preferences before exiting Radiant?", sizeof( text ) ); Sys_Printf( text ); @@ -138,7 +138,7 @@ void WINAPI Error( char *error, ... ){ char text[1024]; va_start( argptr,error ); - vsprintf( text, error,argptr ); + vsnprintf( text, sizeof( text ), error, argptr ); va_end( argptr ); Error( (const char *)text ); diff --git a/radiant/file.cpp b/radiant/file.cpp index 4e655c0f..47f94191 100644 --- a/radiant/file.cpp +++ b/radiant/file.cpp @@ -229,7 +229,7 @@ void MemStream::printf( const char* s, ... ){ char buffer[4096]; va_start( args, s ); - vsprintf( buffer, s, args ); + vsnprintf( buffer, sizeof( buffer ), s, args ); va_end( args ); Write( buffer, strlen( buffer ) ); } diff --git a/radiant/groupdialog.cpp b/radiant/groupdialog.cpp index 211eda02..7b181fde 100644 --- a/radiant/groupdialog.cpp +++ b/radiant/groupdialog.cpp @@ -194,7 +194,7 @@ void GetSpawnFlags( void ){ } else { - sprintf( sz, "%i", f ); + snprintf( sz, sizeof( sz ), "%i", f ); if ( multiple_entities ) { brush_t *b; @@ -564,13 +564,13 @@ bool GetSelectAllCriteria( CString &strKey, CString &strVal ){ void AssignSound(){ char buffer[NAME_MAX]; - strcpy( buffer, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buffer, "sound/" ); + Q_strncpyz( buffer, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buffer ) ); + strncat( buffer, "sound/", sizeof( buffer ) ); if ( access( buffer, R_OK ) != 0 ) { // just go to fsmain - strcpy( buffer, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buffer, "/" ); + Q_strncpyz( buffer, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buffer ) ); + strncat( buffer, "/", sizeof( buffer ) ); } const char *filename = file_dialog( g_pGroupDlg->m_pWidget, TRUE, _( "Open Wav File" ), buffer, "sound" ); @@ -595,13 +595,13 @@ void AssignSound(){ void AssignModel(){ char buffer[NAME_MAX]; - strcpy( buffer, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buffer, "models/" ); + Q_strncpyz( buffer, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buffer ) ); + strncat( buffer, "models/", sizeof( buffer ) ); if ( access( buffer, R_OK ) != 0 ) { // just go to fsmain - strcpy( buffer, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buffer, "/" ); + Q_strncpyz( buffer, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buffer ) ); + strncat( buffer, "/", sizeof( buffer ) ); } const char *filename = file_dialog( g_pGroupDlg->m_pWidget, TRUE, _( "Open Model" ), buffer, MODEL_MAJOR ); diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 44778059..9a9b9071 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -1393,7 +1393,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, entry->name, 1, tmp, -1 ); @@ -1404,11 +1404,11 @@ void DoMapInfo(){ g_object_unref( G_OBJECT( store ) ); char tmp[16]; - sprintf( tmp, "%d", TotalBrushes ); + snprintf( tmp, sizeof( tmp ), "%d", TotalBrushes ); gtk_entry_set_text( GTK_ENTRY( brushes_entry ), tmp ); - sprintf( tmp, "%d", TotalEntities ); + snprintf( tmp, sizeof( tmp ), "%d", TotalEntities ); gtk_entry_set_text( GTK_ENTRY( entities_entry ), tmp ); - sprintf( tmp, "%d", Net ); + snprintf( tmp, sizeof( tmp ), "%d", Net ); gtk_entry_set_text( GTK_ENTRY( net_entry ), tmp ); gtk_grab_add( dlg ); @@ -3264,8 +3264,8 @@ int DoBSInputDlg( const char *fields[5], float values[5] ){ gtk_widget_show( entries[i] ); gtk_box_pack_start( GTK_BOX( vbox ), entries[i], TRUE, TRUE, 0 ); - char buf[32]; - sprintf( buf, "%f", values[i] ); + char buf[64]; + snprintf( buf, sizeof( buf ), "%f", values[i] ); gtk_entry_set_text( GTK_ENTRY( entries[i] ), buf ); } diff --git a/radiant/gtkmisc.cpp b/radiant/gtkmisc.cpp index 215fcd96..fb4f1040 100644 --- a/radiant/gtkmisc.cpp +++ b/radiant/gtkmisc.cpp @@ -1493,11 +1493,11 @@ const char* file_dialog( void *parent, gboolean open, const char* title, const c // we expect an actual path below, if the path is NULL we might crash if ( !path || path[0] == '\0' ) { - strcpy( buf, g_pGameDescription->mEnginePath.GetBuffer() ); - strcat( buf, g_pGameDescription->mBaseGame.GetBuffer() ); - strcat( buf, "/" ); + Q_strncpyz( buf, g_pGameDescription->mEnginePath.GetBuffer(), sizeof( buf ) ); + strncat( buf, g_pGameDescription->mBaseGame.GetBuffer(), sizeof( buf ) ); + strncat( buf, "/", sizeof( buf ) ); if ( baseSubDir ) { - strcat( buf, baseSubDir ); + strncat( buf, baseSubDir, sizeof( buf ) ); } path = buf; } @@ -1547,7 +1547,9 @@ const char* file_dialog( void *parent, gboolean open, const char* title, const c } if ( gtk_dialog_run( GTK_DIALOG( file_sel ) ) == GTK_RESPONSE_ACCEPT ) { - strcpy( szFile, gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( file_sel ) ) ); + gchar * filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( file_sel ) ); + Q_strncpyz( szFile, filename, sizeof( szFile ) ); + g_free( filename ); } else { szFile[0] = '\0'; diff --git a/radiant/main.cpp b/radiant/main.cpp index 31b3801a..0e5610cd 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'; @@ -310,61 +310,61 @@ void error_redirect( const gchar *domain, GLogLevelFlags log_level, const gchar } if ( domain ) { - strcpy( buf, domain ); + Q_strncpyz( buf, domain, sizeof( buf ) ); } else{ - strcpy( buf, "**" ); + Q_strncpyz( buf, "**", sizeof( buf ) ); } - strcat( buf, "-" ); + strncat( buf, "-", sizeof( buf ) ); switch ( log_level ) { case G_LOG_LEVEL_ERROR: if ( in_recursion ) { - strcat( buf, "ERROR (recursed) **: " ); + strncat( buf, "ERROR (recursed) **: ", sizeof( buf ) ); } else{ - strcat( buf, "ERROR **: " ); + strncat( buf, "ERROR **: ", sizeof( buf ) ); } break; case G_LOG_LEVEL_CRITICAL: if ( in_recursion ) { - strcat( buf, "CRITICAL (recursed) **: " ); + strncat( buf, "CRITICAL (recursed) **: ", sizeof( buf ) ); } else{ - strcat( buf, "CRITICAL **: " ); + strncat( buf, "CRITICAL **: ", sizeof( buf ) ); } break; case G_LOG_LEVEL_WARNING: if ( in_recursion ) { - strcat( buf, "WARNING (recursed) **: " ); + strncat( buf, "WARNING (recursed) **: ", sizeof( buf ) ); } else{ - strcat( buf, "WARNING **: " ); + strncat( buf, "WARNING **: ", sizeof( buf ) ); } break; case G_LOG_LEVEL_MESSAGE: if ( in_recursion ) { - strcat( buf, "Message (recursed): " ); + strncat( buf, "Message (recursed): ", sizeof( buf ) ); } else{ - strcat( buf, "Message: " ); + strncat( buf, "Message: ", sizeof( buf ) ); } break; case G_LOG_LEVEL_INFO: if ( in_recursion ) { - strcat( buf, "INFO (recursed): " ); + strncat( buf, "INFO (recursed): ", sizeof( buf ) ); } else{ - strcat( buf, "INFO: " ); + strncat( buf, "INFO: ", sizeof( buf ) ); } break; case G_LOG_LEVEL_DEBUG: if ( in_recursion ) { - strcat( buf, "DEBUG (recursed): " ); + strncat( buf, "DEBUG (recursed): ", sizeof( buf ) ); } else{ - strcat( buf, "DEBUG: " ); + strncat( buf, "DEBUG: ", sizeof( buf ) ); } break; default: @@ -372,10 +372,10 @@ void error_redirect( const gchar *domain, GLogLevelFlags log_level, const gchar * try to make the best out of it. */ if ( in_recursion ) { - strcat( buf, "LOG (recursed:" ); + strncat( buf, "LOG (recursed:", sizeof( buf ) ); } else{ - strcat( buf, "LOG (" ); + strncat( buf, "LOG (", sizeof( buf ) ); } if ( log_level ) { gchar string[] = "0x00): "; @@ -390,19 +390,19 @@ void error_redirect( const gchar *domain, GLogLevelFlags log_level, const gchar *p += 'A' - '9' - 1; } - strcat( buf, string ); + strncat( buf, string, sizeof( buf ) ); } else{ - strcat( buf, "): " ); + strncat( buf, "): ", sizeof( buf ) ); } } - strcat( buf, message ); + strncat( buf, message, sizeof( buf ) ); if ( is_fatal ) { - strcat( buf, "\naborting...\n" ); + strncat( buf, "\naborting...\n", sizeof( buf ) ); } else{ - strcat( buf, "\n" ); + strncat( buf, "\n", sizeof( buf ) ); } printf( "%s\n", buf ); @@ -777,7 +777,7 @@ int mainRadiant( int argc, char* argv[] ) { // remove the game prefs files remove( g_PrefsDlg.m_inipath->str ); char buf[PATH_MAX]; - sprintf( buf, "%sSavedInfo.bin", g_PrefsDlg.m_rc_path->str ); + snprintf( buf, sizeof( buf ), "%sSavedInfo.bin", g_PrefsDlg.m_rc_path->str ); remove( buf ); // remove the global pref too g_PrefsDlg.mGamesDialog.Reset(); @@ -1004,12 +1004,12 @@ void QE_ExpandBspString( char *bspaction, GPtrArray *out_array, char *mapname ){ char rsh[BIG_PATH_MAX]; char base[BIG_PATH_MAX]; - strcpy( src, mapname ); + Q_strncpyz( src, mapname, sizeof( src ) ); strlwr( src ); in = strstr( src, "maps/" ); if ( in ) { in += 5; - strcpy( base, in ); + Q_strncpyz( base, in, sizeof( base ) ); out = base; while ( *out ) { @@ -1021,7 +1021,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 @@ -1036,11 +1036,11 @@ void QE_ExpandBspString( char *bspaction, GPtrArray *out_array, char *mapname ){ if ( g_pGameDescription->mGameFile != "hl.game" && *ValueForKey( g_qeglobals.d_project_entity,"gamename" ) != '\0' ) { // set with fs_game - sprintf( src, "-fs_game %s \"%s\"", ValueForKey( g_qeglobals.d_project_entity,"gamename" ), mapname ); + snprintf( src, sizeof( src ), "-fs_game %s \"%s\"", ValueForKey( g_qeglobals.d_project_entity,"gamename" ), mapname ); } else { - sprintf( src, "\"%s\"", mapname ); + snprintf( src, sizeof( src ), "\"%s\"", mapname ); } rsh[0] = 0; @@ -1049,14 +1049,14 @@ void QE_ExpandBspString( char *bspaction, GPtrArray *out_array, char *mapname ){ // initialise the first step out = new char[BIG_PATH_MAX]; + *out = 0; g_ptr_array_add( out_array, out ); in = ValueForKey( g_qeglobals.d_project_entity, bspaction ); while ( *in ) { if ( in[0] == '!' ) { - strcpy( out, rsh ); - out += strlen( rsh ); + strncat( out, rsh, BIG_PATH_MAX ); in++; continue; } @@ -1066,36 +1066,39 @@ void QE_ExpandBspString( char *bspaction, GPtrArray *out_array, char *mapname ){ if ( g_PrefsDlg.m_bWatchBSP ) { // -connect global option (the only global option so far anyway) strcpy( tmp, " -connect 127.0.0.1:39000 " ); - strcpy( out, tmp ); - out += strlen( tmp ); + strncat( out, tmp, BIG_PATH_MAX ); } in++; continue; } if ( in[0] == '$' ) { // $ expansion - strcpy( out, src ); - out += strlen( src ); + strncat( out, src, BIG_PATH_MAX ); in++; continue; } if ( in[0] == '@' ) { - *out++ = '"'; + strncat( out, "\"", BIG_PATH_MAX ); in++; continue; } if ( in[0] == '&' ) { if ( in[1] == '&' ) { // start a new step - *out = 0; in = in + 2; out = new char[BIG_PATH_MAX]; + *out = 0; g_ptr_array_add( out_array, out ); } } - *out++ = *in++; + size_t len = strlen( out ); + if( ( len + 1 ) < BIG_PATH_MAX ) + { + out[len++] = *in; + out[len] = '\0'; + } + in++; } - *out = 0; } void FindReplace( CString& strContents, const char* pTag, const char* pValue ){ @@ -1114,15 +1117,15 @@ void FindReplace( CString& strContents, const char* pTag, const char* pValue ){ } // save the map, deals with regioning -void SaveWithRegion( char *name ){ - strcpy( name, currentmap ); +void SaveWithRegion( char *name, size_t length ){ + Q_strncpyz( name, currentmap, length ); if ( region_active ) { // temporary cut the region to save regular map region_active = false; Map_SaveFile( name, false ); region_active = true; StripExtension( name ); - strcat( name, ".reg" ); + strncat( name, ".reg", length ); } Map_SaveFile( name, region_active ); @@ -1193,9 +1196,9 @@ void RunBsp( char *command ){ SetInspectorMode( W_CONSOLE ); - strcpy( temppath, g_strTempPath.GetBuffer() ); + Q_strncpyz( temppath, g_strTempPath.GetBuffer(), sizeof( temppath ) ); - SaveWithRegion( name ); + SaveWithRegion( name, sizeof( name ) ); const char *rsh = ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ); if ( rsh == NULL ) { @@ -1203,10 +1206,10 @@ void RunBsp( char *command ){ ExtractPath_and_Filename( name, strPath, strFile ); AddSlash( strPath ); - strncpy( cWork, strPath, 1024 ); - strcat( cWork, strFile ); + Q_strncpyz( cWork, strPath, 1024 ); + strncat( cWork, strFile, sizeof( cWork ) ); } else { - strcpy( cWork, name ); + Q_strncpyz( cWork, name, sizeof( cWork ) ); } // get the array ready @@ -1217,7 +1220,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, 1024 ); StripExtension( bspname ); g_pParentWnd->GetWatchBSP()->DoMonitoringLoop( sys, bspname ); } else { @@ -1243,7 +1246,7 @@ void RunBsp( char *command ){ #if defined ( __linux__ ) || defined ( __APPLE__ ) // write qe3bsp.sh - sprintf( batpath, "%sqe3bsp.sh", temppath ); + snprintf( batpath, sizeof( batpath ), "%sqe3bsp.sh", temppath ); Sys_Printf( "Writing the compile script to '%s'\n", batpath ); hFile = fopen( batpath, "w" ); if ( !hFile ) { @@ -1255,8 +1258,8 @@ void RunBsp( char *command ){ chmod( batpath, 0744 ); #endif -#ifdef _WIN32 - sprintf( batpath, "%sqe3bsp.bat", temppath ); +#if defined( _WIN32 ) || defined( __CYGWIN__ ) + snprintf( batpath, sizeof( batpath ), "%sqe3bsp.bat", temppath ); Sys_Printf( "Writing the compile script to '%s'\n", batpath ); Sys_Printf( "The build output will be saved in '%sjunk.txt'\n", temppath ); hFile = fopen( batpath, "w" ); diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 4fb3b198..59ec3e05 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -2174,7 +2174,7 @@ void clipboard_paste(){ } -#elif defined( WIN32 ) +#elif defined( _WIN32 ) void clipboard_copy(){ Clipboard_CopyMap(); @@ -3435,7 +3435,7 @@ void MainFrame::LoadCommandMap(){ #if defined ( __linux__ ) || defined ( __APPLE__ ) strINI = g_PrefsDlg.m_rc_path->str; -#elif defined( WIN32 ) +#elif defined( _WIN32 ) || defined( __CYGWIN__ ) strINI = g_strGameToolsPath; #else #error "WTF are you compiling this on" @@ -3450,7 +3450,7 @@ void MainFrame::LoadCommandMap(){ for ( int i = 0; i < g_nCommandCount; i++ ) { char value[1024]; - if ( read_var( strINI.GetBuffer(), "Commands", g_Commands[i].m_strCommand, value ) ) { + if ( read_var( strINI.GetBuffer(), "Commands", g_Commands[i].m_strCommand, value, sizeof( value ) ) ) { if ( !bUserCmdList ) { Sys_Printf( "Found user's shortcuts list at %s\n", strINI.GetBuffer() ); bUserCmdList = true; @@ -3683,10 +3683,10 @@ void MainFrame::CreateQEChildren(){ // check to see if the project template is versioned - strcpy( buf, g_pGameDescription->mEnginePath.GetBuffer() ); - strcat( buf, g_pGameDescription->mBaseGame.GetBuffer() ); - strcat( buf, "/scripts/" ); - strcat( buf, PROJECT_TEMPLATE_NAME ); + Q_strncpyz( buf, g_pGameDescription->mEnginePath.GetBuffer(), sizeof( buf ) ); + strncat( buf, g_pGameDescription->mBaseGame.GetBuffer(), sizeof( buf ) ); + strncat( buf, "/scripts/", sizeof( buf ) ); + strncat( buf, PROJECT_TEMPLATE_NAME, sizeof( buf ) ); templateVersion = QE_GetTemplateVersionForProject( buf ); r = g_PrefsDlg.m_strLastProject.GetBuffer(); @@ -3697,10 +3697,10 @@ void MainFrame::CreateQEChildren(){ // try default project location bTriedTemplate = true; // for all OSes, we look for the template in the base installation (no homepath here) - strcpy( buf, g_pGameDescription->mEnginePath.GetBuffer() ); - strcat( buf, g_pGameDescription->mBaseGame.GetBuffer() ); - strcat( buf, "/scripts/" ); - strcat( buf, PROJECT_TEMPLATE_NAME ); + Q_strncpyz( buf, g_pGameDescription->mEnginePath.GetBuffer(), sizeof( buf ) ); + strncat( buf, g_pGameDescription->mBaseGame.GetBuffer(), sizeof( buf ) ); + strncat( buf, "/scripts/", sizeof( buf ) ); + strncat( buf, PROJECT_TEMPLATE_NAME, sizeof( buf ) ); r = buf; } else @@ -3888,7 +3888,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 @@ -3923,7 +3923,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 } @@ -3932,7 +3932,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 @@ -4009,7 +4009,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 } @@ -4258,8 +4258,8 @@ void MainFrame::OnFileOpen(){ char buf[NAME_MAX]; if ( !g_pGameDescription->noMapsInHome ) { - strcpy( buf, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buf, "maps/" ); + Q_strncpyz( buf, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buf ) ); + strncat( buf, "maps/", sizeof( buf ) ); } else { buf[0] = '\0'; @@ -4268,7 +4268,7 @@ void MainFrame::OnFileOpen(){ str = file_dialog( m_pWidget, TRUE, _( "Open Map" ), buf, MAP_MAJOR, "maps/" ); if ( str != NULL ) { - strcpy( currentmap,str ); + Q_strncpyz( currentmap, str, sizeof( currentmap ) ); MRU_AddFile( str ); Map_LoadFile( str ); } @@ -4279,8 +4279,8 @@ void MainFrame::OnFileImportmap(){ char buf[NAME_MAX]; if ( !g_pGameDescription->noMapsInHome ) { - strcpy( buf, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buf, "maps/" ); + Q_strncpyz( buf, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buf ) ); + strncat( buf, "maps/", sizeof( buf ) ); } else { buf[0] = '\0'; @@ -4307,8 +4307,8 @@ void MainFrame::OnFileSaveas(){ char buf[NAME_MAX]; if ( !g_pGameDescription->noMapsInHome ) { - strcpy( buf, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buf, "maps/" ); + Q_strncpyz( buf, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buf ) ); + strncat( buf, "maps/", sizeof( buf ) ); } else { buf[0] = '\0'; @@ -4317,7 +4317,7 @@ void MainFrame::OnFileSaveas(){ str = file_dialog( g_pParentWnd->m_pWidget, FALSE, _( "Save Map" ), buf, MAP_MAJOR, "maps/" ); if ( str != NULL ) { - strcpy( currentmap, str ); + Q_strncpyz( currentmap, str, sizeof( currentmap ) ); MRU_AddFile( str ); Map_SaveFile( str, false ); // ignore region } @@ -4328,8 +4328,8 @@ void MainFrame::OnFileExportmap(){ char buf[NAME_MAX]; if ( !g_pGameDescription->noMapsInHome ) { - strcpy( buf, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buf, "maps/" ); + Q_strncpyz( buf, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buf ) ); + strncat( buf, "maps/", sizeof( buf ) ); } else { buf[0] = '\0'; @@ -4347,8 +4347,8 @@ void MainFrame::OnFileSaveregion(){ char buf[NAME_MAX]; if ( !g_pGameDescription->noMapsInHome ) { - strcpy( buf, g_qeglobals.m_strHomeMaps.GetBuffer() ); - strcat( buf, "maps/" ); + Q_strncpyz( buf, g_qeglobals.m_strHomeMaps.GetBuffer(), sizeof( buf ) ); + strncat( buf, "maps/", sizeof( buf ) ); } else { buf[0] = '\0'; @@ -5716,9 +5716,9 @@ void MainFrame::OnTexturesLoad(){ // FIXME // check if that works with fs_game (I suspect some more design is needed) // see how this is done in 1.2? - strcpy( def_path, g_pGameDescription->mEnginePath.GetBuffer() ); - strcat( def_path, g_pGameDescription->mBaseGame.GetBuffer() ); - strcat( def_path, "/" ); + Q_strncpyz( def_path, g_pGameDescription->mEnginePath.GetBuffer(), sizeof( def_path ) ); + strncat( def_path, g_pGameDescription->mBaseGame.GetBuffer(), sizeof( def_path ) ); + strncat( def_path, "/", sizeof( def_path ) ); char *dir = dir_dialog( m_pWidget, _( "Load textures from path" ), def_path ); @@ -5731,7 +5731,7 @@ void MainFrame::OnTexturesLoad(){ } char *pouic = MAX( strrchr( dir, '/' ),strrchr( dir, '\\' ) ); if ( pouic ) { - strcpy( texture_directory, pouic + 1 ); + Q_strncpyz( texture_directory, pouic + 1, 128 ); Sys_Printf( "Loading '%s'\n", texture_directory ); Texture_ShowDirectory(); } @@ -6156,8 +6156,8 @@ void MainFrame::OnMiscSelectentitycolor(){ } if ( inspector_mode == W_ENTITY && ( DoColor( COLOR_ENTITY ) ) ) { - char buffer[100]; - sprintf( buffer, "%f %f %f", g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][0], + char buffer[256]; + 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 37cf8e99..6f01ed35 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -549,7 +549,7 @@ void Map_LoadFile( const char *filename ){ // used when conversion between standard map format and BP format is required and the user cancels the process g_bCancel_Map_LoadFile = false; - strcpy( currentmap, filename ); + Q_strncpyz( currentmap, filename, sizeof( currentmap ) ); g_bScreenUpdates = false; // leo: avoid redraws while loading the map (see fenris:1952) @@ -778,9 +778,9 @@ void Map_SaveFile( const char *filename, qboolean use_region ){ char backup[1024]; // rename current to .bak - strcpy( backup, filename ); + Q_strncpyz( backup, filename, sizeof( backup ) ); StripExtension( backup ); - strcat( backup, ".bak" ); + strncat( backup, ".bak", sizeof( backup ) ); unlink( backup ); rename( filename, backup ); } @@ -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; @@ -1272,7 +1272,7 @@ void MemFile_fprintf( MemStream* pMemFile, const char* pText, ... ){ char Buffer[4096]; va_list args; va_start( args,pText ); - vsprintf( Buffer, pText, args ); + vsnprintf( Buffer, sizeof( Buffer ), pText, args ); pMemFile->Write( Buffer, strlen( Buffer ) ); } diff --git a/radiant/missing.cpp b/radiant/missing.cpp index c220e62e..3b84d804 100644 --- a/radiant/missing.cpp +++ b/radiant/missing.cpp @@ -115,7 +115,7 @@ bool radCreateDirectory( const char *directory, bool fatal_on_error ) { int GetFullPathName( const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart ){ if ( lpFileName[0] == '/' ) { - strcpy( lpBuffer, lpFileName ); + Q_strncpyz( lpBuffer, lpFileName, nBufferLength ); *lpFilePart = strrchr( lpBuffer, '/' ); return strlen( lpBuffer ); } @@ -124,9 +124,9 @@ int GetFullPathName( const char *lpFileName, int nBufferLength, char *lpBuffer, return 0; } - strcat( lpBuffer, "/" ); + strncat( lpBuffer, "/", nBufferLength ); *lpFilePart = lpBuffer + strlen( lpBuffer ); - strcat( lpBuffer, lpFileName ); + strncat( lpBuffer, lpFileName, nBufferLength ); char *scr = lpBuffer, *dst = lpBuffer; for ( int i = 0; ( i < nBufferLength ) && ( *scr != 0 ); i++ ) diff --git a/radiant/pluginentities.cpp b/radiant/pluginentities.cpp index 1f0ad082..2c384335 100644 --- a/radiant/pluginentities.cpp +++ b/radiant/pluginentities.cpp @@ -33,7 +33,7 @@ #endif //#include "qe3.h" -int QERApp_EClassScanDir( char *path, void* hPlug ){ +int QERApp_EClassScanDir( const char *path, void* hPlug ){ char temp[NAME_MAX]; char filebase[NAME_MAX]; char filename[NAME_MAX]; @@ -43,7 +43,7 @@ int QERApp_EClassScanDir( char *path, void* hPlug ){ struct dirent *dirlist; QE_ConvertDOSToUnixName( temp, path ); - strcpy( filebase, path ); + Q_strncpyz( filebase, path, sizeof( filebase ) ); s = filebase + strlen( filebase ) - 1; while ( *s != '\\' && *s != '/' && s != filebase ) s--; @@ -53,7 +53,7 @@ int QERApp_EClassScanDir( char *path, void* hPlug ){ if ( dir != NULL ) { while ( ( dirlist = readdir( dir ) ) != NULL ) { - sprintf( filename, "%s/%s", filebase, dirlist->d_name ); + snprintf( filename, sizeof( filename ), "%s/%s", filebase, dirlist->d_name ); Eclass_ScanFile( filename ); if ( eclass_found ) { diff --git a/radiant/pluginmanager.cpp b/radiant/pluginmanager.cpp index 3a9929c8..40a28a54 100644 --- a/radiant/pluginmanager.cpp +++ b/radiant/pluginmanager.cpp @@ -495,7 +495,11 @@ CPluginSlot::~CPluginSlot(){ void CPluginSlot::Init(){ CString str = mpTable->m_pfnQERPlug_GetCommandList(); char cTemp[1024]; - strcpy( cTemp, str ); + Q_strncpyz( cTemp, str, sizeof( cTemp ) ); + if( str.GetLength() > sizeof( cTemp ) - 1 ) + { + Sys_FPrintf( SYS_WRN, "WARNING: Temporary buffer is too small in CPluginSlot::Init\n" ); + } char* token = strtok( cTemp, ",;" ); if ( token && *token == ' ' ) { while ( *token == ' ' ) @@ -1090,7 +1094,7 @@ _QERFaceData* WINAPI QERApp_GetFaceData( void* pv, int nFaceIndex ){ face.m_fShift[0] = f->texdef.shift[0]; face.m_fShift[1] = f->texdef.shift[1]; } - strcpy( face.m_TextureName, f->texdef.GetName() ); + Q_strncpyz( face.m_TextureName, f->texdef.GetName(), sizeof( face.m_TextureName ) ); VectorCopy( f->planepts[0], face.m_v1 ); VectorCopy( f->planepts[1], face.m_v2 ); VectorCopy( f->planepts[2], face.m_v3 ); @@ -1298,7 +1302,7 @@ char* WINAPI QERApp_GetTexture( int nIndex ){ break; } if ( n == nIndex ) { - strcpy( name, pShader->getName() ); + Q_strncpyz( name, pShader->getName(), sizeof( name ) ); return name; } n++; @@ -1308,7 +1312,7 @@ char* WINAPI QERApp_GetTexture( int nIndex ){ char* WINAPI QERApp_GetCurrentTexture(){ static char current_tex[1024]; - strcpy( current_tex,g_qeglobals.d_texturewin.texdef.GetName() ); + Q_strncpyz( current_tex, g_qeglobals.d_texturewin.texdef.GetName(), sizeof( current_tex ) ); return current_tex; } @@ -1518,7 +1522,7 @@ int QERApp_ScriptLine(){ // we save the map and return the name .. either .map or .reg to support region compiling char* QERApp_GetMapName(){ static char name[PATH_MAX]; - SaveWithRegion( name ); + SaveWithRegion( name, sizeof( name ) ); return name; } diff --git a/radiant/pmesh.cpp b/radiant/pmesh.cpp index 041cd7ce..280ef539 100644 --- a/radiant/pmesh.cpp +++ b/radiant/pmesh.cpp @@ -4755,7 +4755,7 @@ void Patch_AdjustSelected( bool bInsert, bool bColumn, bool bFlag ){ strategies that call here too much are known to be slow patch 84 to bug 253 adds an additionnal check for textures/ */ -void CheckName( patchMesh_t *p, char *pname ){ +void CheckName( patchMesh_t *p, char *pname, size_t length ){ if ( strncmp( p->pShader->getName(), "textures/", 9 ) != 0 ) { p->pShader = QERApp_Shader_ForName( SHADER_NOT_FOUND ); } @@ -4763,15 +4763,15 @@ void CheckName( patchMesh_t *p, char *pname ){ // some manage to get long filename textures (with spaces) in their maps if ( strchr( p->pShader->getName(), ' ' ) ) { char Msg1[1024]; - sprintf( Msg1, "Can't save texture with spaces in name. Rename %s\nNOTE: This message may popup several times .. once for each buggy face detected.", p->pShader->getName() ); + snprintf( Msg1, sizeof( Msg1 ), "Can't save texture with spaces in name. Rename %s\nNOTE: This message may popup several times .. once for each buggy face detected.", p->pShader->getName() ); Sys_Printf( "%s\n", Msg1 ); gtk_MessageBox( g_pParentWnd->m_pWidget, Msg1, "Error saving map", MB_OK ); - strcpy( pname, SHADER_NOT_FOUND ); + Q_strncpyz( pname, SHADER_NOT_FOUND, length ); p->pShader = QERApp_Shader_ForName( SHADER_NOT_FOUND ); p->d_texture = p->pShader->getTexture(); return; } - strcpy( pname, p->pShader->getName() + 9 ); // remove "textures/" + Q_strncpyz( pname, p->pShader->getName() + 9, length ); // remove "textures/" } /* @@ -4784,7 +4784,7 @@ void Patch_Write( patchMesh_t *p, MemStream *file ){ MemFile_fprintf( file, " {\n patchDef2\n {\n" ); - CheckName( p, pname ); + CheckName( p, pname, sizeof( pname ) ); MemFile_fprintf( file, " %s\n", pname ); MemFile_fprintf( file, " ( %i %i %i %i %i ) \n", p->width, p->height, p->contents, p->flags, p->value ); @@ -4823,7 +4823,7 @@ void Patch_Write( patchMesh_t *p, FILE *file ){ fprintf( file, " {\n patchDef2\n {\n" ); { - CheckName( p, pname ); + CheckName( p, pname, sizeof( pname ) ); fprintf( file, " %s\n", pname ); fprintf( file, " ( %i %i %i %i %i ) \n", p->width, p->height, p->contents, p->flags, p->value ); } diff --git a/radiant/points.cpp b/radiant/points.cpp index b0e8e4bf..130b809f 100644 --- a/radiant/points.cpp +++ b/radiant/points.cpp @@ -72,9 +72,9 @@ void CPointfile::GenerateDisplayList(){ void Pointfile_Delete( void ){ char name[1024]; - strcpy( name, currentmap ); + Q_strncpyz( name, currentmap, sizeof( name ) ); StripExtension( name ); - strcat( name, ".lin" ); + strncat( name, ".lin", sizeof( name ) ); remove( name ); } @@ -125,9 +125,9 @@ void WINAPI Pointfile_Check( void ){ int line = 1; vec3_t v; - strcpy( name, currentmap ); + Q_strncpyz( name, currentmap, sizeof( name ) ); StripExtension( name ); - strcat( name, ".lin" ); + strncat( name, ".lin", sizeof( name ) ); size = vfsLoadFullPathFile( name, (void**)&data ); if ( size <= 0 ) { diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 31432b3e..6f576f8f 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; } @@ -307,8 +307,8 @@ void CXMLPropertyBag::GetPref( const char *name, int *pV, int V ){ } else { - char s[10]; - sprintf( s, "%d", V ); + char s[12]; + snprintf( s, sizeof( s ), "%d", V ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); *pV = V; @@ -347,8 +347,8 @@ void CXMLPropertyBag::GetPref( const char *name, float *pV, float V ){ } else { - char s[10]; - sprintf( s, "%f", V ); + char s[64]; + snprintf( s, sizeof( s ), "%f", V ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); *pV = V; @@ -364,8 +364,8 @@ void CXMLPropertyBag::GetPref( const char *name, float* pV, float* V ){ } else { - char s[128]; - sprintf( s, "%f %f %f", V[0], V[1], V[2] ); + char s[256]; + 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]; @@ -401,7 +401,7 @@ void CXMLPropertyBag::UpdatePrefTree(){ CPrefAssignment *pPref = &( *iPref ); // look for the node xmlNodePtr pNode; - char s[64]; + char s[256]; pNode = EpairForName( pPref->mName.GetBuffer() ); // we never expect that the node could not be found, because this is supposed to happen @@ -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; @@ -501,7 +501,7 @@ qboolean CXMLPropertyBag::WriteXMLFile( const char* pFilename ){ // ============================================================================= // Widget callbacks for PrefsDlg -#if !defined( WIN32 ) +#if !defined( _WIN32 ) // browse for custom editor executable static void OnBtnBrowseEditor( GtkWidget *widget, gpointer data ){ PrefsDlg *dlg = (PrefsDlg*)data; @@ -523,7 +523,7 @@ static void OnBtnBrowseprefab( GtkWidget *widget, gpointer data ){ if ( strlen( path ) == 0 ) { path = g_strGameToolsPath; } - char *dir = dir_dialog( g_PrefsDlg.GetWidget(), _( "Set prefab path" ), path ); + gchar *dir = dir_dialog( g_PrefsDlg.GetWidget(), _( "Set prefab path" ), path ); dlg->UpdateData( TRUE ); if ( dir != NULL ) { @@ -564,7 +564,7 @@ static void OnButtonClean( GtkWidget *widget, gpointer data ){ g_qeglobals.disable_ini = true; remove( dlg->m_inipath->str ); char buf[PATH_MAX]; - sprintf( buf, "%sSavedInfo.bin", dlg->m_rc_path->str ); + snprintf( buf, sizeof( buf ), "%sSavedInfo.bin", dlg->m_rc_path->str ); remove( buf ); HandleCommand( NULL, GINT_TO_POINTER( ID_FILE_EXIT ) ); _exit( 0 ); @@ -729,9 +729,9 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const Str &GameFile ){ { char full[PATH_MAX]; #ifdef _WIN32 - _fullpath( full, prop, PATH_MAX ); + _fullpath( full, prop, sizeof( full ) ); #else - strncpy( full, prop, PATH_MAX ); + Q_strncpyz( full, prop, sizeof( full ) ); #endif xmlFree( prop ); prop = NULL; @@ -822,9 +822,9 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const Str &GameFile ){ if ( prop != NULL ) { char full[PATH_MAX]; #ifdef _WIN32 - _fullpath( full, prop, PATH_MAX ); + _fullpath( full, prop, sizeof( full ) ); #else - strncpy( full, prop, PATH_MAX ); + Q_strncpyz( full, prop, sizeof( full ) ); #endif xmlFree( prop ); prop = NULL; @@ -844,12 +844,12 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const Str &GameFile ){ // if engine path was not specified in the .game, it implies we can guess it from the gametools path // on win32, and for most game package, the gametools are installed with the game char aux_path[PATH_MAX]; // aux - strcpy( aux_path, mGameToolsPath.GetBuffer() ); + Q_strncpyz( aux_path, mGameToolsPath.GetBuffer(), sizeof( aux_path ) ); if ( ( aux_path[ strlen( aux_path ) - 1 ] == '/' ) || ( aux_path[ strlen( aux_path ) - 1 ] == '\\' ) ) { 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; } } @@ -3087,7 +3087,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], "" ); } @@ -3130,7 +3130,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] ); } @@ -3154,7 +3154,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 dc6200b0..acbb9ead 100644 --- a/radiant/profile.cpp +++ b/radiant/profile.cpp @@ -46,7 +46,7 @@ // ============================================================================= // Static functions -bool read_var( const char *filename, const char *section, const char *key, char *value ){ +bool read_var( const char *filename, const char *section, const char *key, char *value, size_t length ){ char line[1024], *ptr; FILE *rc; @@ -83,7 +83,7 @@ bool read_var( const char *filename, const char *section, const char *key, char line[strlen( line ) - 1] = '\0'; if ( strcmp( line, key ) == 0 ) { - strcpy( value, ptr + 1 ); + Q_strncpyz( value, ptr + 1, length ); fclose( rc ); if ( value[strlen( value ) - 1] == 10 || value[strlen( value ) - 1] == 13 || value[strlen( value ) - 1] == 32 ) { @@ -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[16]; - sprintf( buf, "%f", value ); + char buf[64]; + snprintf( buf, sizeof( buf ), "%f", value ); return save_var( filename, section, key, buf ); } @@ -204,7 +204,7 @@ bool WINAPI profile_save_string( const char * filename, const char *section, con bool profile_save_buffer( const char * rc_path, const char *name, void *buffer, guint32 size ){ bool ret = false; char filename[PATH_MAX]; - sprintf( filename, "%s/%s.bin", rc_path, name ); + snprintf( filename, sizeof( filename ), "%s/%s.bin", rc_path, name ); FILE *f; f = fopen( filename, "wb" ); @@ -222,7 +222,7 @@ bool profile_save_buffer( const char * rc_path, const char *name, void *buffer, bool profile_load_buffer( const char * rc_path, const char *name, void *buffer, guint32 *plSize ){ char filename[PATH_MAX]; - sprintf( filename, "%s/%s.bin", rc_path, name ); + snprintf( filename, sizeof( filename ), "%s/%s.bin", rc_path, name ); bool ret = false; guint32 len; FILE *f; @@ -254,7 +254,7 @@ bool profile_load_buffer( const char * rc_path, const char *name, void *buffer, int WINAPI profile_load_int( const char *filename, const char *section, const char *key, int default_value ){ char value[1024]; - if ( read_var( filename, section, key, value ) ) { + if ( read_var( filename, section, key, value, sizeof( value ) ) ) { return atoi( value ); } else{ @@ -265,7 +265,7 @@ int WINAPI profile_load_int( const char *filename, const char *section, const ch float WINAPI profile_load_float( const char *filename, const char *section, const char *key, float default_value ){ char value[1024]; - if ( read_var( filename, section, key, value ) ) { + if ( read_var( filename, section, key, value, sizeof( value ) ) ) { return atof( value ); } else{ @@ -277,7 +277,7 @@ char* WINAPI profile_load_string( const char *filename, const char *section, con static Str ret; char value[1024]; - if ( read_var( filename, section, key, value ) ) { + if ( read_var( filename, section, key, value, sizeof( value ) ) ) { ret = value; } else{ diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 1904aa41..9bfa6080 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -100,7 +100,7 @@ void WINAPI QE_CheckOpenGLForErrors( void ){ int i = qglGetError(); if ( i != GL_NO_ERROR ) { if ( i == GL_OUT_OF_MEMORY ) { - sprintf( strMsg, "OpenGL out of memory error %s\nDo you wish to save before exiting?", qgluErrorString( (GLenum)i ) ); + snprintf( strMsg, sizeof( strMsg ), "OpenGL out of memory error %s\nDo you wish to save before exiting?", qgluErrorString( (GLenum)i ) ); if ( gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg, "Radiant Error", MB_YESNO ) == IDYES ) { Map_SaveFile( NULL, false ); } @@ -126,14 +126,14 @@ char *ExpandReletivePath( char *p ){ } base = ValueForKey( g_qeglobals.d_project_entity, "basepath" ); - sprintf( temp, "%s/%s", base, p ); + snprintf( temp, sizeof( temp ), "%s/%s", base, p ); return temp; } char *copystring( char *s ){ char *b; b = (char*)malloc( strlen( s ) + 1 ); - strcpy( b,s ); + strcpy( b, s ); return b; } @@ -197,7 +197,7 @@ void Map_Snapshot(){ char buf[PATH_MAX]; //sprintf( buf, "%s.%i", strNewPath.GetBuffer(), nCount ); // snapshot will now end with a known ext. - sprintf( buf, "%s.%i.%s", strNewPath.GetBuffer(), nCount, strOldEXT.GetBuffer() ); + snprintf( buf, sizeof( buf ), "%s.%i.%s", strNewPath.GetBuffer(), nCount, strOldEXT.GetBuffer() ); strFile = buf; bGo = DoesFileExist( strFile, lSize ); nCount++; @@ -282,7 +282,7 @@ int BuildShortPathName( 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; } @@ -354,7 +354,7 @@ void HandleXMLError( void* ctxt, const char* text, ... ){ static char buf[32768]; va_start( argptr,text ); - vsprintf( buf, text, argptr ); + vsnprintf( buf, sizeof( buf ), text, argptr ); Sys_FPrintf( SYS_ERR, "XML %s\n", buf ); va_end( argptr ); } @@ -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 = ""; @@ -645,7 +646,7 @@ bool QE_LoadProject( const char *projectfile ){ if ( IntForKey( g_qeglobals.d_project_entity, "version" ) != PROJECT_VERSION ) { char strMsg[2048]; - sprintf( strMsg, + snprintf( strMsg, sizeof( strMsg ), "The template project '%s' has version %d. The editor binary is configured for version %d.\n" "This indicates a problem in your setup.\n" "I will keep going with this project till you fix this", @@ -654,19 +655,19 @@ bool QE_LoadProject( const char *projectfile ){ } // create the writable project file path - strcpy( buf, g_qeglobals.m_strHomeGame.GetBuffer() ); - strcat( buf, g_pGameDescription->mBaseGame.GetBuffer() ); - strcat( buf, G_DIR_SEPARATOR_S "scripts" G_DIR_SEPARATOR_S ); + Q_strncpyz( buf, g_qeglobals.m_strHomeGame.GetBuffer(), sizeof( buf ) ); + strncat( buf, g_pGameDescription->mBaseGame.GetBuffer(), sizeof( buf ) ); + strncat( buf, G_DIR_SEPARATOR_S "scripts" G_DIR_SEPARATOR_S, sizeof( buf ) ); // while the filename is already in use, increment the number we add to the end int counter = 0; char pUser[PATH_MAX]; while ( 1 ) { - sprintf( pUser, "%suser%d." PROJECT_FILETYPE, buf, counter ); + snprintf( pUser, sizeof( pUser ), "%suser%d." PROJECT_FILETYPE, buf, counter ); counter++; if ( access( pUser, R_OK ) != 0 ) { // this is the one - strcpy( buf, pUser ); + Q_strncpyz( buf, pUser, sizeof( buf ) ); break; } } @@ -1266,7 +1267,7 @@ void Sys_MarkMapModified( void ){ if ( modified != 1 ) { modified = true; // mark the map as changed - sprintf( title, "%s *", currentmap ); + snprintf( title, sizeof( title ), "%s *", currentmap ); QE_ConvertDOSToUnixName( title, title ); Sys_SetTitle( title ); @@ -1337,7 +1338,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 ); } @@ -1372,11 +1373,11 @@ void buffer_write_escaped_mnemonic( char* buffer, const char* string ){ } static void MRU_SetText( int index, const char *filename ){ - strcpy( MRU_filenames[index], filename ); + Q_strncpyz( MRU_filenames[index], filename, sizeof( MRU_filenames[index] ) ); 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 ); @@ -1510,9 +1511,9 @@ void ProjectDialog(){ * store it in buffer. */ - strcpy( buffer, g_qeglobals.m_strHomeGame.GetBuffer() ); - strcat( buffer, g_pGameDescription->mBaseGame.GetBuffer() ); - strcat( buffer, "/scripts/" ); + Q_strncpyz( buffer, g_qeglobals.m_strHomeGame.GetBuffer(), sizeof( buffer ) ); + strncat( buffer, g_pGameDescription->mBaseGame.GetBuffer(), sizeof( buffer ) ); + strncat( buffer, "/scripts/", sizeof( buffer ) ); // Display the Open dialog box filename = file_dialog( NULL, TRUE, _( "Open File" ), buffer, "project" ); @@ -1569,7 +1570,7 @@ void FillBSPMenu(){ if ( g_qeglobals.bBSPFrontendPlugin ) { CString str = g_BSPFrontendTable.m_pfnGetBSPMenu(); char cTemp[1024]; - strcpy( cTemp, str ); + Q_strncpyz( cTemp, str, sizeof( cTemp ) ); char* token = strtok( cTemp, ",;" ); if ( token && *token == ' ' ) { while ( *token == ' ' ) diff --git a/radiant/qe3.h b/radiant/qe3.h index ed755385..23a5d34f 100644 --- a/radiant/qe3.h +++ b/radiant/qe3.h @@ -271,7 +271,7 @@ int WINAPI profile_load_int( const char *filename, const char *section, const ch float WINAPI profile_load_float( const char *filename, const char *section, const char *key, float default_value ); char* WINAPI profile_load_string( const char *filename, const char *section, const char *key, const char *default_value ); // used in the command map code -bool read_var( const char *filename, const char *section, const char *key, char *value ); +bool read_var( const char *filename, const char *section, const char *key, char *value, size_t length ); // // entityw.c @@ -793,7 +793,7 @@ extern void CheckBspProcess(); extern void QE_CountBrushesAndUpdateStatusBar(); extern void QE_CheckAutoSave(); extern qtexture_t *current_texture; -extern void SaveWithRegion( char *name ); // save the current map, sets the map name in the name buffer (deals with regioning) +extern void SaveWithRegion( char *name, size_t length ); // save the current map, sets the map name in the name buffer (deals with regioning) extern void RunBsp( char *command ); extern void Map_Snapshot(); extern void WXY_Print(); diff --git a/radiant/select.cpp b/radiant/select.cpp index b0584136..c28ef4e2 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/selectedface.cpp b/radiant/selectedface.cpp index f0a90ed5..4cab7356 100644 --- a/radiant/selectedface.cpp +++ b/radiant/selectedface.cpp @@ -60,7 +60,7 @@ int WINAPI QERApp_GetFaceInfo( int iface, _QERFaceData *pFaceData, winding_t *pW return 0; } face_t *selFace = reinterpret_cast( g_ptrSelectedFaces.GetAt( iface ) ); - strcpy( pFaceData->m_TextureName, selFace->texdef.GetName() ); + Q_strncpyz( pFaceData->m_TextureName, selFace->texdef.GetName(), sizeof( pFaceData->m_TextureName ) ); VectorCopy( selFace->planepts[0], pFaceData->m_v1 ); VectorCopy( selFace->planepts[1], pFaceData->m_v2 ); VectorCopy( selFace->planepts[2], pFaceData->m_v3 ); diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index 08f106fe..97307db3 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -929,12 +929,8 @@ void SurfaceDlg::SetTexMods(){ } GtkAdjustment *adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); adjust->step_increment = l_pIncrement->shift[0]; - char buf[10]; // got into snprintf paranoia after BoundChecker detected a stack overrun -#ifdef _WIN32 - // TTimo: THIS IS UGLY -#define snprintf _snprintf -#endif - snprintf( buf, 10, "%g", l_pIncrement->shift[0] ); + char buf[64]; // got into snprintf paranoia after BoundChecker detected a stack overrun + snprintf( buf, sizeof( buf ), "%g", l_pIncrement->shift[0] ); gtk_entry_set_text( GTK_ENTRY( GetDlgWidget( "hshift_inc" ) ), buf ); spin = GTK_SPIN_BUTTON( GetDlgWidget( "vshift" ) ); @@ -947,7 +943,7 @@ void SurfaceDlg::SetTexMods(){ } adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); adjust->step_increment = l_pIncrement->shift[1]; - snprintf( buf, 10, "%g", l_pIncrement->shift[1] ); + snprintf( buf, sizeof( buf ), "%g", l_pIncrement->shift[1] ); gtk_entry_set_text( GTK_ENTRY( GetDlgWidget( "vshift_inc" ) ), buf ); spin = GTK_SPIN_BUTTON( GetDlgWidget( "hscale" ) ); @@ -956,7 +952,7 @@ void SurfaceDlg::SetTexMods(){ adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); adjust->step_increment = l_pIncrement->scale[0]; - snprintf( buf, 10, "%g", l_pIncrement->scale[0] ); + snprintf( buf, sizeof( buf ), "%g", l_pIncrement->scale[0] ); gtk_entry_set_text( GTK_ENTRY( GetDlgWidget( "hscale_inc" ) ), buf ); spin = GTK_SPIN_BUTTON( GetDlgWidget( "vscale" ) ); @@ -965,7 +961,7 @@ void SurfaceDlg::SetTexMods(){ adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); adjust->step_increment = l_pIncrement->scale[1]; - snprintf( buf, 10, "%g", l_pIncrement->scale[1] ); + snprintf( buf, sizeof( buf ), "%g", l_pIncrement->scale[1] ); gtk_entry_set_text( GTK_ENTRY( GetDlgWidget( "vscale_inc" ) ), buf ); //++timo compute BProtate as int .. @@ -975,7 +971,7 @@ void SurfaceDlg::SetTexMods(){ adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); adjust->step_increment = l_pIncrement->rotate; - snprintf( buf, 10, "%g", l_pIncrement->rotate ); + snprintf( buf, sizeof( buf ), "%g", l_pIncrement->rotate ); gtk_entry_set_text( GTK_ENTRY( GetDlgWidget( "rotate_inc" ) ), buf ); g_bListenChanged = true; @@ -1036,7 +1032,7 @@ void SurfaceDlg::GetTexMods(){ else { strcpy( buffer, "textures/" ); - strcpy( buffer + 9, text ); + Q_strncpyz( buffer + 9, text, sizeof( buffer ) - 9 ); pt->SetName( buffer ); } 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 ec20e357..ecf31463 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -494,7 +494,7 @@ void BuildShaderList(){ } if ( g_pGameDescription->mGameFile != "hl.game" ) { - strcpy( filename, g_pGameDescription->mShaderlist.GetBuffer() ); + Q_strncpyz( filename, g_pGameDescription->mShaderlist.GetBuffer(), sizeof( filename ) ); count = vfsGetFileCount( filename, 0 ); if ( count == 0 ) { Sys_FPrintf( SYS_ERR, "Couldn't find '%s'\n", g_pGameDescription->mShaderlist.GetBuffer() ); @@ -603,7 +603,7 @@ void FillTextureMenu( 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 ); @@ -749,7 +749,7 @@ void Texture_ShowDirectory(){ // need this function "GSList *lst SynapseServer::GetMinorList(char *major_name);" - sprintf( dirstring, "textures/%s", texture_directory ); + snprintf( dirstring, sizeof( dirstring ), "textures/%s", texture_directory ); g_ImageManager.BeginExtensionsScan(); const char* ext; while ( ( ext = g_ImageManager.GetNextExtension() ) != NULL ) @@ -759,7 +759,7 @@ void Texture_ShowDirectory(){ for ( temp = files; temp; temp = temp->next ) { - sprintf( name, "%s%s", texture_directory, (char*)temp->data ); + snprintf( name, sizeof( name ), "%s%s", texture_directory, (char*)temp->data ); StripExtension( name ); strTemp = name; @@ -792,7 +792,7 @@ void Texture_ShowDirectory(){ // build a texture name that fits the conventions for qtexture_t::name char stdName[1024]; - sprintf( stdName, "textures/%s", name ); + snprintf( stdName, sizeof( stdName ), "textures/%s", name ); // check if this texture doesn't have a shader if ( !QERApp_ActiveShader_ForTextureName( stdName ) ) { QERApp_CreateShader_ForTextureName( stdName ); @@ -808,7 +808,7 @@ void Texture_ShowDirectory(){ // sort for displaying QERApp_SortActiveShaders(); - sprintf( name, "Textures: %s", texture_directory ); + snprintf( name, sizeof( name ), "Textures: %s", texture_directory ); gtk_window_set_title( GTK_WINDOW( g_qeglobals_gui.d_entity ), name ); // select the first texture in the list @@ -831,7 +831,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(); } @@ -911,7 +911,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 ); } @@ -966,7 +966,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 ); @@ -1000,7 +1000,7 @@ void Texture_ShowStartupShaders(){ int nLen; GSList *shaderfiles = NULL; - strcpy( filename, g_pGameDescription->mShaderlist.GetBuffer() ); + Q_strncpyz( filename, g_pGameDescription->mShaderlist.GetBuffer(), sizeof( filename ) ); count = vfsGetFileCount( filename, 0 ); if ( count == 0 ) { Sys_FPrintf( SYS_ERR, "Couldn't find '%s'\n", g_pGameDescription->mShaderlist.GetBuffer() ); @@ -1023,7 +1023,7 @@ void Texture_ShowStartupShaders(){ bool found = false; // each token should be a shader filename - sprintf( dirstring, "%s.shader", token ); + snprintf( dirstring, sizeof( dirstring ), "%s.shader", token ); for ( tmp = shaderfiles; tmp != NULL; tmp = tmp->next ) { @@ -1036,7 +1036,7 @@ void Texture_ShowStartupShaders(){ if ( !found ) { shaderfiles = g_slist_append( l_shaderfiles, strdup( dirstring ) ); - strcpy( texture_directory, dirstring ); + Q_strncpyz( texture_directory, dirstring, sizeof( texture_directory ) ); Texture_ShowDirectory(); nLen++; } diff --git a/radiant/watchbsp.cpp b/radiant/watchbsp.cpp index 0e0c9c87..4ef8f2df 100644 --- a/radiant/watchbsp.cpp +++ b/radiant/watchbsp.cpp @@ -191,7 +191,7 @@ static void saxWarning( void *ctx, const char *msg, ... ){ va_list args; va_start( args, msg ); - vsprintf( saxMsgBuffer, msg, args ); + vsnprintf( saxMsgBuffer, sizeof( saxMsgBuffer ), msg, args ); va_end( args ); Sys_FPrintf( SYS_WRN, "XML warning: %s\n", saxMsgBuffer ); } @@ -201,7 +201,7 @@ static void saxError( void *ctx, const char *msg, ... ){ va_list args; va_start( args, msg ); - vsprintf( saxMsgBuffer, msg, args ); + vsnprintf( saxMsgBuffer, sizeof( saxMsgBuffer ), msg, args ); va_end( args ); Sys_FPrintf( SYS_ERR, "XML error: %s\n", saxMsgBuffer ); } @@ -212,7 +212,7 @@ static void saxFatal( void *ctx, const char *msg, ... ){ va_list args; va_start( args, msg ); - vsprintf( buffer, msg, args ); + vsnprintf( buffer, sizeof( buffer ), msg, args ); va_end( args ); Sys_FPrintf( SYS_ERR, "XML fatal error: %s\n", buffer ); } diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 53c58ffe..fa68e8ae 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -430,7 +430,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 ); } } @@ -446,8 +446,8 @@ void CreateEntityFromName( const char* name, const vec3_t origin ){ // prompt.GotoDlgCtrl( pWnd ); if ( DoLightIntensityDlg( &intensity ) == IDOK ) { g_PrefsDlg.m_iLastLightIntensity = intensity; - char buf[10]; - sprintf( buf, "%d", intensity ); + char buf[12]; + snprintf( buf, sizeof( buf ), "%d", intensity ); SetKeyValue( e, "light", buf ); } } @@ -2287,14 +2287,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 ); } @@ -2460,7 +2460,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/quake2/common/cmdlib.c b/tools/quake2/common/cmdlib.c index 34286363..aa8f625f 100644 --- a/tools/quake2/common/cmdlib.c +++ b/tools/quake2/common/cmdlib.c @@ -27,7 +27,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #endif @@ -93,7 +93,7 @@ char archivedir[1024]; #define MAX_EX_ARGC 1024 int ex_argc; char *ex_argv[MAX_EX_ARGC]; -#ifdef WIN32 +#ifdef _WIN32 #include "io.h" void ExpandWildcards( int *argc, char ***argv ){ struct _finddata_t fileinfo; @@ -328,7 +328,7 @@ double I_FloatTime( void ){ void Q_getwd( char *out ){ int i = 0; -#ifdef WIN32 +#ifdef _WIN32 _getcwd( out, 256 ); strcat( out, "\\" ); #else @@ -347,7 +347,7 @@ void Q_getwd( char *out ){ void Q_mkdir( const char *path ){ -#ifdef WIN32 +#ifdef _WIN32 if ( _mkdir( path ) != -1 ) { return; } @@ -1128,7 +1128,7 @@ void CreatePath( const char *path ){ char c; char dir[1024]; -#ifdef WIN32 +#ifdef _WIN32 int olddrive = -1; if ( path[1] == ':' ) { @@ -1151,7 +1151,7 @@ void CreatePath( const char *path ){ } } -#ifdef WIN32 +#ifdef _WIN32 if ( olddrive != -1 ) { _chdrive( olddrive ); } @@ -1177,7 +1177,7 @@ void QCopyFile( const char *from, const char *to ){ } void Sys_Sleep( int n ){ -#ifdef WIN32 +#ifdef _WIN32 Sleep( n ); #endif #if defined ( __linux__ ) || defined ( __APPLE__ ) diff --git a/tools/quake2/common/cmdlib.h b/tools/quake2/common/cmdlib.h index 6cc5fade..acca4aa4 100644 --- a/tools/quake2/common/cmdlib.h +++ b/tools/quake2/common/cmdlib.h @@ -32,7 +32,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #ifdef NDEBUG // Don't show in a Release build #pragma warning(disable : 4305) // truncate from double to float #pragma warning(disable : 4244) // conversion from double to float @@ -40,7 +40,7 @@ #endif #endif -#ifdef WIN32 +#ifdef _WIN32 #pragma intrinsic( memset, memcpy ) #endif diff --git a/tools/quake2/common/inout.c b/tools/quake2/common/inout.c index d99ad195..0fd397d6 100644 --- a/tools/quake2/common/inout.c +++ b/tools/quake2/common/inout.c @@ -33,7 +33,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #endif @@ -46,7 +46,7 @@ #endif #include "libxml/tree.h" -#ifdef WIN32 +#ifdef _WIN32 HWND hwndOut = NULL; qboolean lookedForServer = false; UINT wm_BroadcastCommand = -1; diff --git a/tools/quake2/common/qfiles.h b/tools/quake2/common/qfiles.h index 29d9647d..c01f4c3f 100644 --- a/tools/quake2/common/qfiles.h +++ b/tools/quake2/common/qfiles.h @@ -32,7 +32,7 @@ ======================================================================== */ -#ifdef WIN32 +#ifdef _WIN32 #ifdef NDEBUG // Don't show in a Release build #pragma warning(disable : 4305) // truncate from double to float #pragma warning(disable : 4244) // conversion from double to float diff --git a/tools/quake2/common/threads.c b/tools/quake2/common/threads.c index 98dd86b5..28cb36bf 100644 --- a/tools/quake2/common/threads.c +++ b/tools/quake2/common/threads.c @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef WIN32 +#ifndef _WIN32 // The below define is necessary to use // pthreads extensions like pthread_mutexattr_settype #define _GNU_SOURCE @@ -106,7 +106,7 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( =================================================================== */ -#ifdef WIN32 +#ifdef _WIN32 #define USED diff --git a/tools/quake2/extra/bsp/qrad3/qrad.h b/tools/quake2/extra/bsp/qrad3/qrad.h index 67025460..6878fd43 100644 --- a/tools/quake2/extra/bsp/qrad3/qrad.h +++ b/tools/quake2/extra/bsp/qrad3/qrad.h @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "threads.h" #include "lbmlib.h" -#ifdef WIN32 +#ifdef _WIN32 #include #endif diff --git a/tools/quake2/extra/common/cmdlib.c b/tools/quake2/extra/common/cmdlib.c index 60f615a0..3d15d34f 100644 --- a/tools/quake2/extra/common/cmdlib.c +++ b/tools/quake2/extra/common/cmdlib.c @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #endif @@ -305,7 +305,7 @@ double I_FloatTime (void) void Q_getwd (char *out) { -#ifdef WIN32 +#ifdef _WIN32 _getcwd (out, 256); strcat (out, "\\"); #else @@ -317,7 +317,7 @@ void Q_getwd (char *out) void Q_mkdir (char *path) { -#ifdef WIN32 +#ifdef _WIN32 if (_mkdir (path) != -1) return; #else diff --git a/tools/quake2/extra/common/threads.c b/tools/quake2/extra/common/threads.c index 25a87c78..a816f3c9 100644 --- a/tools/quake2/extra/common/threads.c +++ b/tools/quake2/extra/common/threads.c @@ -99,7 +99,7 @@ WIN32 =================================================================== */ -#ifdef WIN32 +#ifdef _WIN32 #define USED diff --git a/tools/quake2/extra/qe4/mru.c b/tools/quake2/extra/qe4/mru.c index 84a5a3eb..8a019748 100644 --- a/tools/quake2/extra/qe4/mru.c +++ b/tools/quake2/extra/qe4/mru.c @@ -505,7 +505,7 @@ WORD i; return TRUE; } -#ifdef WIN32 +#ifdef _WIN32 BOOL IsWin395OrHigher(void) { diff --git a/tools/quake2/extra/qe4/mru.h b/tools/quake2/extra/qe4/mru.h index b78b986c..4b05b974 100644 --- a/tools/quake2/extra/qe4/mru.h +++ b/tools/quake2/extra/qe4/mru.h @@ -83,7 +83,7 @@ void PlaceMenuMRUItem(LPMRUMENU lpMruMenu,HMENU hMenu,UINT uiItem); BOOL SaveMruInIni (LPMRUMENU lpMruMenu,LPSTR lpszSection,LPSTR lpszFile); BOOL LoadMruInIni (LPMRUMENU lpMruMenu,LPSTR lpszSection,LPSTR lpszFile); -#ifdef WIN32 +#ifdef _WIN32 BOOL SaveMruInReg (LPMRUMENU lpMruMenu,LPSTR lpszKey); BOOL LoadMruInReg (LPMRUMENU lpMruMenu,LPSTR lpszKey); diff --git a/tools/quake2/q2map/q2map.h b/tools/quake2/q2map/q2map.h index 0b262093..5c2ed4ac 100644 --- a/tools/quake2/q2map/q2map.h +++ b/tools/quake2/q2map/q2map.h @@ -31,7 +31,7 @@ #include #endif -#ifdef WIN32 +#ifdef _WIN32 #include #endif diff --git a/tools/quake2/q2map/qbsp.h b/tools/quake2/q2map/qbsp.h index bd55ba40..51bb52db 100644 --- a/tools/quake2/q2map/qbsp.h +++ b/tools/quake2/q2map/qbsp.h @@ -46,7 +46,7 @@ #include "bspfile.h" #include "inout.h" -#ifdef WIN32 +#ifdef _WIN32 #ifdef NDEBUG // Don't show in a Release build #pragma warning(disable : 4305) // truncate from double to float #pragma warning(disable : 4244) // conversion from double to float diff --git a/tools/quake2/q2map/qrad.h b/tools/quake2/q2map/qrad.h index 8801cc4c..67005717 100644 --- a/tools/quake2/q2map/qrad.h +++ b/tools/quake2/q2map/qrad.h @@ -36,11 +36,11 @@ #include "lbmlib.h" #include "inout.h" -#ifdef WIN32 +#ifdef _WIN32 #include #endif -#ifdef WIN32 +#ifdef _WIN32 #ifdef NDEBUG // Don't show in a Release build #pragma warning(disable : 4305) // truncate from double to float #pragma warning(disable : 4244) // conversion from double to float diff --git a/tools/quake2/q2map/qvis.h b/tools/quake2/q2map/qvis.h index a268f2cf..d209b8ba 100644 --- a/tools/quake2/q2map/qvis.h +++ b/tools/quake2/q2map/qvis.h @@ -30,7 +30,7 @@ #include "bspfile.h" #include "inout.h" -#ifdef WIN32 +#ifdef _WIN32 #ifdef NDEBUG // Don't show in a Release build #pragma warning(disable : 4305) // truncate from double to float #pragma warning(disable : 4244) // conversion from double to float diff --git a/tools/quake2/qdata/qdata.h b/tools/quake2/qdata/qdata.h index fe500246..1cbe0fc4 100644 --- a/tools/quake2/qdata/qdata.h +++ b/tools/quake2/qdata/qdata.h @@ -34,7 +34,7 @@ #include "l3dslib.h" #include "bspfile.h" -#ifdef WIN32 +#ifdef _WIN32 #ifdef NDEBUG // Don't show in a Release build #pragma warning(disable : 4305) // truncate from double to float #pragma warning(disable : 4244) // conversion from double to float diff --git a/tools/quake2/qdata_heretic2/common/cmdlib.c b/tools/quake2/qdata_heretic2/common/cmdlib.c index a9980168..a08ad0db 100644 --- a/tools/quake2/qdata_heretic2/common/cmdlib.c +++ b/tools/quake2/qdata_heretic2/common/cmdlib.c @@ -27,7 +27,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #endif @@ -342,7 +342,7 @@ double I_FloatTime( void ){ void Q_getwd( char *out ){ int i = 0; -#ifdef WIN32 +#ifdef _WIN32 _getcwd( out, 256 ); strcat( out, "\\" ); #else @@ -361,7 +361,7 @@ void Q_getwd( char *out ){ void Q_mkdir( const char *path ){ -#ifdef WIN32 +#ifdef _WIN32 if ( _mkdir( path ) != -1 ) { return; } @@ -1189,7 +1189,7 @@ void QCopyFile( const char *from, const char *to ){ } void Sys_Sleep( int n ){ -#ifdef WIN32 +#ifdef _WIN32 Sleep( n ); #endif #if defined ( __linux__ ) || defined ( __APPLE__ ) diff --git a/tools/quake2/qdata_heretic2/common/inout.c b/tools/quake2/qdata_heretic2/common/inout.c index d99ad195..0fd397d6 100644 --- a/tools/quake2/qdata_heretic2/common/inout.c +++ b/tools/quake2/qdata_heretic2/common/inout.c @@ -33,7 +33,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #endif @@ -46,7 +46,7 @@ #endif #include "libxml/tree.h" -#ifdef WIN32 +#ifdef _WIN32 HWND hwndOut = NULL; qboolean lookedForServer = false; UINT wm_BroadcastCommand = -1; diff --git a/tools/quake2/qdata_heretic2/common/threads.c b/tools/quake2/qdata_heretic2/common/threads.c index 2468cdde..22587f66 100644 --- a/tools/quake2/qdata_heretic2/common/threads.c +++ b/tools/quake2/qdata_heretic2/common/threads.c @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef WIN32 +#ifndef _WIN32 // The below define is necessary to use // pthreads extensions like pthread_mutexattr_settype #define _GNU_SOURCE @@ -106,7 +106,7 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( =================================================================== */ -#ifdef WIN32 +#ifdef _WIN32 #define USED diff --git a/tools/quake3/common/aselib.c b/tools/quake3/common/aselib.c index 3e49696c..485c0d0a 100644 --- a/tools/quake3/common/aselib.c +++ b/tools/quake3/common/aselib.c @@ -157,7 +157,7 @@ void ASE_Load( const char *filename, qboolean verbose, qboolean grabAnims ){ fclose( fp ); - strcpy( gl_filename, filename ); + Q_strncpyz( gl_filename, filename, sizeof( gl_filename ) ); ASE_Process(); } @@ -243,8 +243,8 @@ polyset_t *ASE_GetSurfaceAnimation( int which, int *pNumFrames, int skipFrameSta } } - strcpy( psets[f].name, pObject->name ); - strcpy( psets[f].materialname, ase.materials[pObject->materialRef].name ); + Q_strncpyz( psets[f].name, pObject->name, sizeof( psets[f].name ) ); + Q_strncpyz( psets[f].materialname, ase.materials[pObject->materialRef].name, sizeof( psets[f].materialname ) ); psets[f].triangles = calloc( sizeof( triangle_t ) * pObject->anim.frames[i].numFaces, 1 ); psets[f].numtriangles = pObject->anim.frames[i].numFaces; @@ -415,7 +415,7 @@ static void ASE_KeyMAP_DIFFUSE( const char *token ){ char filename[1024]; int i = 0, count; - strcpy( filename, gl_filename ); + Q_strncpyz( filename, gl_filename, sizeof( filename ) ); if ( !strcmp( token, "*BITMAP" ) ) { ASE_GetToken( qfalse ); @@ -423,7 +423,7 @@ static void ASE_KeyMAP_DIFFUSE( const char *token ){ // the purpose of this whole chunk of code below is to extract the relative path // from a full path in the ASE - strcpy( bitmap, s_token + 1 ); + Q_strncpyz( bitmap, s_token + 1, sizeof( bitmap ) ); if ( strchr( bitmap, '"' ) ) { *strchr( bitmap, '"' ) = 0; } @@ -458,20 +458,22 @@ static void ASE_KeyMAP_DIFFUSE( const char *token ){ break; } } - strcpy( bitmap, &bitmap[3] ); + Q_strncpyz( bitmap, &bitmap[3], sizeof( bitmap ) ); } - strcat( filename, "/" ); - strcat( filename, bitmap ); - strcpy( bitmap, filename ); + strncat( filename, "/", sizeof( filename ) ); + strncat( filename, bitmap, sizeof( filename ) ); + Q_strncpyz( bitmap, filename, sizeof( bitmap ) ); } if ( strstr( bitmap, gamedir ) ) { - strcpy( ase.materials[ase.numMaterials].name, strstr( bitmap, gamedir ) + strlen( gamedir ) ); + Q_strncpyz( ase.materials[ase.numMaterials].name, + strstr( bitmap, gamedir ) + strlen( gamedir ), + sizeof( ase.materials[ase.numMaterials].name )); Sys_Printf( "material name: \'%s\'\n", strstr( bitmap, gamedir ) + strlen( gamedir ) ); } else { - sprintf( ase.materials[ase.numMaterials].name, "(not converted: '%s')", bitmap ); + snprintf( ase.materials[ase.numMaterials].name, sizeof( ase.materials[ase.numMaterials].name ), "(not converted: '%s')", bitmap ); Sys_Printf( "WARNING: illegal material name '%s'\n", bitmap ); } } @@ -608,13 +610,13 @@ static void ASE_KeyMESH_TVERTLIST( const char *token ){ ASE_GetToken( qfalse ); ASE_GetToken( qfalse ); - strcpy( u, s_token ); + Q_strncpyz( u, s_token, sizeof( u ) ); ASE_GetToken( qfalse ); - strcpy( v, s_token ); + Q_strncpyz( v, s_token, sizeof( v ) ); ASE_GetToken( qfalse ); - strcpy( w, s_token ); + Q_strncpyz( w, s_token, sizeof( w ) ); pMesh->tvertexes[pMesh->currentVertex].s = atof( u ); pMesh->tvertexes[pMesh->currentVertex].t = 1.0f - atof( v ); @@ -724,7 +726,7 @@ static void ASE_KeyGEOMOBJECT( const char *token ){ ASE_GetToken( qtrue ); VERBOSE( ( " %s\n", s_token ) ); - strcpy( ase.objects[ase.currentObject].name, s_token + 1 ); + Q_strncpyz( ase.objects[ase.currentObject].name, s_token + 1, sizeof( ase.objects[ase.currentObject].name ) ); if ( strchr( ase.objects[ase.currentObject].name, '"' ) ) { *strchr( ase.objects[ase.currentObject].name, '"' ) = 0; } diff --git a/tools/quake3/common/bspfile.c b/tools/quake3/common/bspfile.c index a5d5fbaf..43334d74 100644 --- a/tools/quake3/common/bspfile.c +++ b/tools/quake3/common/bspfile.c @@ -626,20 +626,20 @@ void UnparseEntities( void ) { continue; // ent got removed } - strcat( end,"{\n" ); + strncat( end, "{\n", sizeof( dentdata ) + dentdata - end ); end += 2; for ( ep = entities[i].epairs ; ep ; ep = ep->next ) { - 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 ); - sprintf( line, "\"%s\" \"%s\"\n", key, value ); - strcat( end, line ); + snprintf( line, sizeof( line ), "\"%s\" \"%s\"\n", key, value ); + strncat( end, line, sizeof( end ) ); end += strlen( line ); } - strcat( end,"}\n" ); + strncat( end, "}\n", sizeof( dentdata ) + dentdata - end ); end += 2; if ( end > buf + MAX_MAP_ENTSTRING ) { diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 94c260d3..e1a5abc9 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -120,11 +120,11 @@ void ExpandWildcards( int *argc, char ***argv ){ return; } - ExtractFilePath( path, filebase ); + ExtractFilePath( path, filebase, sizeof( filebase ) ); do { - sprintf( filename, "%s%s", filebase, fileinfo.name ); + snprintf( filename, sizeof( filename ), "%s%s", filebase, fileinfo.name ); ex_argv[ex_argc++] = copystring( filename ); } while ( _findnext( handle, &fileinfo ) != -1 ); @@ -162,7 +162,7 @@ void SetQdirFromPath( const char *path ){ if ( !( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) ) { // path is partial Q_getwd( temp ); - strcat( temp, path ); + strncat( temp, path, sizeof( temp ) ); path = temp; } @@ -211,7 +211,7 @@ void SetQdirFromPath( const char *path ){ Sys_Printf( "gamedir: %s\n", gamedir ); if ( !writedir[0] ) { - strcpy( writedir, gamedir ); + Q_strncpyz( writedir, gamedir, sizeof( writedir ) ); } else if ( writedir[strlen( writedir ) - 1] != '/' ) { writedir[strlen( writedir )] = '/'; @@ -234,10 +234,10 @@ char *ExpandArg( const char *path ){ if ( path[0] != '/' && path[0] != '\\' && path[1] != ':' ) { Q_getwd( full ); - strcat( full, path ); + strncat( full, path, sizeof( full ) ); } else{ - strcpy( full, path ); + Q_strncpyz( full, path, sizeof( full ) ); } return full; } @@ -245,10 +245,10 @@ char *ExpandArg( const char *path ){ char *ExpandPath( const char *path ){ static char full[1024]; if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) { - strcpy( full, path ); + Q_strncpyz( full, path, sizeof( full ) ); return full; } - sprintf( full, "%s%s", qdir, path ); + snprintf( full, sizeof( full ), "%s%s", qdir, path ); return full; } @@ -292,13 +292,13 @@ double I_FloatTime( void ){ void Q_getwd( char *out ){ int i = 0; -#ifdef WIN32 +#ifdef _WIN32 _getcwd( out, 256 ); - strcat( out, "\\" ); + strncat( out, "\\", sizeof( out ) ); #else // Gef: Changed from getwd() to getcwd() to avoid potential buffer overflow getcwd( out, 256 ); - strcat( out, "/" ); + strncat( out, "/", sizeof( out ) ); #endif while ( out[i] != 0 ) { @@ -311,7 +311,7 @@ void Q_getwd( char *out ){ void Q_mkdir( const char *path ){ -#ifdef WIN32 +#ifdef _WIN32 if ( _mkdir( path ) != -1 ) { return; } @@ -682,7 +682,7 @@ void SaveFile( const char *filename, const void *buffer, int count ){ -void DefaultExtension( char *path, const char *extension ){ +void DefaultExtension( char *path, const char *extension, size_t length ){ char *src; // // if path doesnt have a .EXT, append extension @@ -698,7 +698,7 @@ void DefaultExtension( char *path, const char *extension ){ src--; } - strcat( path, extension ); + strncat( path, extension, length ); } @@ -708,9 +708,9 @@ void DefaultPath( char *path, const char *basepath ){ if ( path[ 0 ] == '/' || path[ 0 ] == '\\' ) { return; // absolute path location } - strcpy( temp,path ); - strcpy( path,basepath ); - strcat( path,temp ); + Q_strncpyz( temp, path, sizeof( temp ) ); + Q_strncpyz( path, basepath, sizeof( path ) ); + strncat( path, temp, sizeof( path ) ); } @@ -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 ){ +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 ){ return; } - strcpy( dest,src ); + Q_strncpyz( dest, src, size ); } @@ -1078,7 +1092,7 @@ void QCopyFile( const char *from, const char *to ){ } void Sys_Sleep( int n ){ -#ifdef WIN32 +#ifdef _WIN32 Sleep( n ); #endif #if defined ( __linux__ ) || defined ( __APPLE__ ) diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index e8d6326f..2a5e7453 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -75,6 +75,12 @@ char *strlower( char *in ); int Q_strncasecmp( const char *s1, const char *s2, int n ); int Q_stricmp( const char *s1, const char *s2 ); void Q_getwd( char *out ); +#define Q_strncpyz(_dst, _source, _len) do { strncpy((_dst), (_source), (_len) - 1); (_dst)[(_len) - 1] = 0; } while( 0 ) + +#if defined(_MSC_VER) && _MSC_VER<1900 && !(defined snprintf) +#define snprintf _snprintf +#endif + int Q_filelength( FILE *f ); int FileTime( const char *path ); @@ -107,14 +113,14 @@ int TryLoadFile( const char *filename, void **bufferptr ); void SaveFile( const char *filename, const void *buffer, int count ); qboolean FileExists( const char *filename ); -void DefaultExtension( char *path, const char *extension ); +void DefaultExtension( char *path, const char *extension, size_t length ); 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 ); +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/imagelib.c b/tools/quake3/common/imagelib.c index e857c73a..3176e65d 100644 --- a/tools/quake3/common/imagelib.c +++ b/tools/quake3/common/imagelib.c @@ -823,7 +823,7 @@ void LoadBMP( const char *filename, byte **pic, byte **palette, int *width, int void Load256Image( const char *name, byte **pixels, byte **palette, int *width, int *height ){ char ext[128]; - ExtractFileExtension( name, ext ); + ExtractFileExtension( name, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "lbm" ) ) { LoadLBM( name, pixels, palette ); if ( width ) { @@ -856,7 +856,7 @@ void Save256Image( const char *name, byte *pixels, byte *palette, int width, int height ){ char ext[128]; - ExtractFileExtension( name, ext ); + ExtractFileExtension( name, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "lbm" ) ) { WriteLBMfile( name, pixels, width, height, palette ); } @@ -1193,7 +1193,7 @@ void Load32BitImage( const char *name, unsigned **pixels, int *width, int *heig int i; int v; - ExtractFileExtension( name, ext ); + ExtractFileExtension( name, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "tga" ) ) { LoadTGA( name, (byte **)pixels, width, height ); } diff --git a/tools/quake3/common/inout.c b/tools/quake3/common/inout.c index ac62549c..d8ac4101 100644 --- a/tools/quake3/common/inout.c +++ b/tools/quake3/common/inout.c @@ -33,7 +33,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #endif @@ -49,7 +49,7 @@ // utf8 conversion #include -#ifdef WIN32 +#ifdef _WIN32 HWND hwndOut = NULL; qboolean lookedForServer = qfalse; UINT wm_BroadcastCommand = -1; @@ -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; @@ -150,20 +150,20 @@ void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ){ char level[2]; // now build a proper "select" XML node - sprintf( buf, "Entity %i, Brush %i: %s", entitynum, brushnum, msg ); + snprintf( buf, sizeof( buf ), "Entity %i, Brush %i: %s", entitynum, brushnum, msg ); node = xmlNewNode( NULL, "select" ); xmlNodeSetContent( node, buf ); level[0] = (int)'0' + ( bError ? SYS_ERR : SYS_WRN ) ; 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 ); xml_SendNode( node ); - sprintf( buf, "Entity %i, Brush %i: %s", entitynum, brushnum, msg ); + snprintf( buf, sizeof( buf ), "Entity %i, Brush %i: %s", entitynum, brushnum, msg ); if ( bError ) { Error( buf ); } @@ -184,13 +184,13 @@ void xml_Point( char *msg, vec3_t pt ){ level[1] = 0; xmlSetProp( node, "level", (char *)&level ); // a 'point' node - sprintf( buf, "%g %g %g", pt[0], pt[1], pt[2] ); + snprintf( buf, sizeof( buf ), "%g %g %g", pt[0], pt[1], pt[2] ); point = xmlNewNode( NULL, "point" ); xmlNodeSetContent( point, buf ); xmlAddChild( node, point ); xml_SendNode( node ); - sprintf( buf, "%s (%g %g %g)", msg, pt[0], pt[1], pt[2] ); + snprintf( buf, sizeof( buf ), "%s (%g %g %g)", msg, pt[0], pt[1], pt[2] ); Error( buf ); } @@ -208,15 +208,15 @@ 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++ ) { - sprintf( smlbuf, "(%g %g %g)", p[i][0], p[i][1], p[i][2] ); + snprintf( smlbuf, sizeof( smlbuf ), "(%g %g %g)", p[i][0], p[i][1], p[i][2] ); // don't overflow if ( strlen( buf ) + strlen( smlbuf ) > WINDING_BUFSIZE ) { break; } - strcat( buf, smlbuf ); + strncat( buf, smlbuf, sizeof( buf ) ); } winding = xmlNewNode( NULL, "winding" ); @@ -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 ); @@ -316,7 +316,7 @@ void Sys_FPrintf( int flag, const char *format, ... ){ } va_start( argptr, format ); - vsprintf( out_buffer, format, argptr ); + vsnprintf( out_buffer, sizeof( out_buffer ), format, argptr ); va_end( argptr ); FPrintf( flag, out_buffer ); @@ -327,7 +327,7 @@ void Sys_Printf( const char *format, ... ){ va_list argptr; va_start( argptr, format ); - vsprintf( out_buffer, format, argptr ); + vsnprintf( out_buffer, sizeof( out_buffer ), format, argptr ); va_end( argptr ); FPrintf( SYS_STD, out_buffer ); @@ -346,10 +346,10 @@ void Error( const char *error, ... ){ va_list argptr; va_start( argptr,error ); - vsprintf( tmp, error, argptr ); + vsnprintf( tmp, sizeof( tmp ), error, argptr ); va_end( argptr ); - sprintf( out_buffer, "************ ERROR ************\n%s\n", tmp ); + snprintf( out_buffer, sizeof( out_buffer ), "************ ERROR ************\n%s\n", tmp ); FPrintf( SYS_ERR, out_buffer ); diff --git a/tools/quake3/common/mutex.c b/tools/quake3/common/mutex.c index c9242f11..33e64276 100644 --- a/tools/quake3/common/mutex.c +++ b/tools/quake3/common/mutex.c @@ -31,7 +31,7 @@ =================================================================== */ -#ifdef WIN32 +#ifdef _WIN32 #define USED diff --git a/tools/quake3/common/scriplib.c b/tools/quake3/common/scriplib.c index acd8d5ad..496e03ae 100644 --- a/tools/quake3/common/scriplib.c +++ b/tools/quake3/common/scriplib.c @@ -63,7 +63,7 @@ void AddScriptToStack( const char *filename, int index ){ if ( script == &scriptstack[MAX_INCLUDES] ) { Error( "script file exceeded MAX_INCLUDES" ); } - strcpy( script->filename, ExpandPath( filename ) ); + Q_strncpyz( script->filename, ExpandPath( filename ), sizeof( script->filename ) ); size = vfsLoadFile( script->filename, (void **)&script->buffer, index ); @@ -111,7 +111,7 @@ void ParseFromMemory( char *buffer, int size ){ if ( script == &scriptstack[MAX_INCLUDES] ) { Error( "script file exceeded MAX_INCLUDES" ); } - strcpy( script->filename, "memory buffer" ); + Q_strncpyz( script->filename, "memory buffer", sizeof( script->filename ) ); script->buffer = buffer; script->line = 1; diff --git a/tools/quake3/common/threads.c b/tools/quake3/common/threads.c index 7b66e8b8..46c79862 100644 --- a/tools/quake3/common/threads.c +++ b/tools/quake3/common/threads.c @@ -106,7 +106,7 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( =================================================================== */ -#ifdef WIN32 +#ifdef _WIN32 #define USED diff --git a/tools/quake3/common/trilib.c b/tools/quake3/common/trilib.c index 67714768..728de766 100644 --- a/tools/quake3/common/trilib.c +++ b/tools/quake3/common/trilib.c @@ -151,7 +151,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) } while ( name[i] != '\0' ); if ( i != 0 ) { - strncpy( pPSET[pset].name, name, sizeof( pPSET[pset].name ) - 1 ); + Q_strncpyz( pPSET[pset].name, name, sizeof( pPSET[pset].name ) ); } else{ strcpy( pPSET[pset].name, "(unnamed)" ); @@ -202,7 +202,7 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets ) } while ( name[i] != '\0' ); if ( i != 0 ) { - strncpy( pPSET[pset].name, name, sizeof( pPSET[pset].name ) - 1 ); + Q_strncpyz( pPSET[pset].name, name, sizeof( pPSET[pset].name ) ); } else{ strcpy( pPSET[pset].name, "(unnamed)" ); diff --git a/tools/quake3/common/vfs.c b/tools/quake3/common/vfs.c index 04af830e..5620501b 100644 --- a/tools/quake3/common/vfs.c +++ b/tools/quake3/common/vfs.c @@ -85,11 +85,11 @@ static gboolean g_bUsePak = TRUE; // ============================================================================= // Static functions -static void vfsAddSlash( char *str ){ +static void vfsAddSlash( char *str, size_t length ){ int n = strlen( str ); if ( n > 0 ) { if ( str[n - 1] != '\\' && str[n - 1] != '/' ) { - strcat( str, "/" ); + strncat( str, "/", length ); } } } @@ -176,9 +176,9 @@ void vfsInitDirectory( const char *path ){ Sys_Printf( "VFS Init: %s\n", path ); - 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] ); + vfsAddSlash( g_strDirs[g_numDirs], sizeof( g_strDirs[g_numDirs] ) ); g_numDirs++; if ( g_bUsePak ) { @@ -201,7 +201,7 @@ void vfsInitDirectory( const char *path ){ } } - sprintf( filename, "%s/%s", path, dirlist ); + snprintf( filename, sizeof( filename ), "%s/%s", path, dirlist ); vfsInitPakFile( filename ); g_free( dirlist ); @@ -234,7 +234,7 @@ int vfsGetFileCount( const char *filename ){ char fixed[NAME_MAX], tmp[NAME_MAX]; GSList *lst; - strcpy( fixed, filename ); + Q_strncpyz( fixed, filename, sizeof( fixed ) ); vfsFixDOSName( fixed ); g_strdown( fixed ); @@ -249,8 +249,8 @@ int vfsGetFileCount( const char *filename ){ for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, fixed ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, fixed, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { count++; } @@ -294,14 +294,14 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){ } *bufferptr = NULL; - strcpy( fixed, filename ); + Q_strncpyz( fixed, filename, sizeof( fixed ) ); vfsFixDOSName( fixed ); g_strdown( fixed ); for ( i = 0; i < g_numDirs; i++ ) { - strcpy( tmp, g_strDirs[i] ); - strcat( tmp, filename ); + Q_strncpyz( tmp, g_strDirs[i], sizeof( tmp ) ); + strncat( tmp, filename, sizeof( tmp ) ); if ( access( tmp, R_OK ) == 0 ) { if ( count == index ) { long len; diff --git a/tools/quake3/q3data/3dslib.c b/tools/quake3/q3data/3dslib.c index 64c7cb07..48894414 100644 --- a/tools/quake3/q3data/3dslib.c +++ b/tools/quake3/q3data/3dslib.c @@ -149,52 +149,52 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat Q_getwd( curdir ); if ( mat.texture[0] ) { - sprintf( buffer, "%s%s", curdir, mat.texture ); + 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] ) { - sprintf( buffer, "%s%s", curdir, mat.specular ); + 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] ) { - sprintf( buffer, "%s%s", curdir, mat.bump ); + 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] ) { - sprintf( buffer, "%s%s", curdir, mat.reflection ); + 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] ) { - sprintf( buffer, "%s%s", curdir, mat.opacity ); + 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; @@ -584,19 +584,19 @@ void _3DS_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets, pPSET[i].triangles = ptri; pPSET[i].numtriangles = pTO->numFaces; - strcpy( pPSET[i].name, _3ds.editChunk.pNamedObjects[i].name ); + Q_strncpyz( pPSET[i].name, _3ds.editChunk.pNamedObjects[i].name, sizeof( pPSET[i].name ) ); - strcpy( matnamebuf, filename ); + Q_strncpyz( matnamebuf, filename, sizeof( matnamebuf ) ); if ( strrchr( matnamebuf, '/' ) ) { *( strrchr( matnamebuf, '/' ) + 1 ) = 0; } - strcat( matnamebuf, pTO->pMeshMaterialGroups[0].name ); + strncat( matnamebuf, pTO->pMeshMaterialGroups[0].name, sizeof( matnamebuf ) ); if ( strstr( matnamebuf, gamedir ) ) { - strcpy( pPSET[i].materialname, strstr( matnamebuf, gamedir ) + strlen( gamedir ) ); + Q_strncpyz( pPSET[i].materialname, strstr( matnamebuf, gamedir ) + strlen( gamedir ), sizeof( pPSET[i].materialname ) ); } else{ - strcpy( pPSET[i].materialname, pTO->pMeshMaterialGroups[0].name ); + Q_strncpyz( pPSET[i].materialname, pTO->pMeshMaterialGroups[0].name, sizeof( pPSET[i].materialname ) ); } assert( pPSET[i].numtriangles < POLYSET_MAXTRIANGLES ); diff --git a/tools/quake3/q3data/md3lib.c b/tools/quake3/q3data/md3lib.c index 78805b44..ae79753a 100644 --- a/tools/quake3/q3data/md3lib.c +++ b/tools/quake3/q3data/md3lib.c @@ -20,7 +20,7 @@ */ #include -#ifdef WIN32 +#ifdef _WIN32 #include #endif #include "md3lib.h" 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/p3dlib.c b/tools/quake3/q3data/p3dlib.c index 9127e8fc..4154838f 100644 --- a/tools/quake3/q3data/p3dlib.c +++ b/tools/quake3/q3data/p3dlib.c @@ -21,7 +21,7 @@ #include "p3dlib.h" -#ifdef WIN32 +#ifdef _WIN32 #include #endif #include diff --git a/tools/quake3/q3data/q3data.c b/tools/quake3/q3data/q3data.c index 50774834..90115d9e 100644 --- a/tools/quake3/q3data/q3data.c +++ b/tools/quake3/q3data/q3data.c @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef WIN32 +#ifdef _WIN32 #include #endif #include "q3data.h" @@ -334,7 +334,7 @@ void PackDirectory_r( char *dir ){ #else #include -#ifndef WIN32 +#ifndef _WIN32 #include #else #include @@ -650,7 +650,7 @@ int main( int argc, char **argv ){ printf( "--------------- %s ---------------\n", argv[i] ); // load the script strcpy( path, argv[i] ); - DefaultExtension( path, ".qdt" ); + DefaultExtension( path, ".qdt", sizeof( path ) ); if ( !gamedir[0] ) { SetQdirFromPath( path ); } diff --git a/tools/quake3/q3data/video.c b/tools/quake3/q3data/video.c index 7fceb79c..93d3828e 100644 --- a/tools/quake3/q3data/video.c +++ b/tools/quake3/q3data/video.c @@ -851,10 +851,10 @@ cblock_t LoadFrame( char *base, int frame, int digits, byte **palette ){ ten0 = frame % 10; if ( digits == 4 ) { - sprintf( name, "%svideo/%s/%s%i%i%i%i.tga", gamedir, base, base, ten3, ten2, ten1, ten0 ); + snprintf( name, sizeof( name ), "%svideo/%s/%s%i%i%i%i.tga", gamedir, base, base, ten3, ten2, ten1, ten0 ); } else{ - sprintf( name, "%svideo/%s/%s%i%i%i.tga", gamedir, base, base, ten2, ten1, ten0 ); + snprintf( name, sizeof( name ), "%svideo/%s/%s%i%i%i.tga", gamedir, base, base, ten2, ten1, ten0 ); } f = fopen( name, "rb" ); @@ -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 384933d6..7e28f327 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -75,7 +75,7 @@ static void ProcessAdvertisements( void ) { else { if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) { bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" ); - strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) ); + Q_strncpyz( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) ); modelKey++; modelNum = atoi( modelKey ); @@ -127,7 +127,7 @@ static void ProcessAdvertisements( void ) { static void SetCloneModelNumbers( void ){ int i, j; int models; - char modelValue[ 10 ]; + char modelValue[ 16 ]; const char *value, *value2, *value3; @@ -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!) */ @@ -420,7 +420,7 @@ void ProcessWorldModel( void ){ /* ydnar: fog hull */ value = ValueForKey( &entities[ 0 ], "_foghull" ); if ( value[ 0 ] != '\0' ) { - sprintf( shader, "textures/%s", value ); + snprintf( shader, sizeof( shader ), "textures/%s", value ); MakeFogHullSurfs( e, tree, shader ); } @@ -630,7 +630,7 @@ void OnlyEnts( void ){ /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); - sprintf( out, "%s.bsp", source ); + snprintf( out, sizeof( out ), "%s.bsp", source ); LoadBSPFile( out ); numEntities = 0; @@ -681,7 +681,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" ); @@ -857,27 +857,27 @@ int BSPMain( int argc, char **argv ){ } /* copy source name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); StripExtension( source ); /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); /* delete portal, line and surface files */ - sprintf( path, "%s.prt", source ); + snprintf( path, sizeof( path ), "%s.prt", source ); remove( path ); - sprintf( path, "%s.lin", source ); + snprintf( path, sizeof( path ), "%s.lin", source ); remove( path ); //% sprintf( path, "%s.srf", source ); /* ydnar */ //% remove( path ); /* expand mapname */ - strcpy( name, ExpandArg( argv[ i ] ) ); + Q_strncpyz( name, ExpandArg( argv[ i ] ), sizeof( name ) ); if ( strcmp( name + strlen( name ) - 4, ".reg" ) ) { /* if we are doing a full map, delete the last saved region map */ - sprintf( path, "%s.reg", source ); + snprintf( path, sizeof( path ), "%s.reg", source ); remove( path ); - DefaultExtension( name, ".map" ); /* might be .reg */ + DefaultExtension( name, ".map", sizeof( name ) ); /* might be .reg */ } /* if onlyents, just grab the entites and resave */ diff --git a/tools/quake3/q3map2/bsp_info.c b/tools/quake3/q3map2/bsp_info.c index 2cc79cf1..285a96a5 100644 --- a/tools/quake3/q3map2/bsp_info.c +++ b/tools/quake3/q3map2/bsp_info.c @@ -61,11 +61,11 @@ int BSPInfoMain( int count, char **fileNames ){ /* mangle filename and get size */ strcpy( source, fileNames[ i ] ); - ExtractFileExtension( source, ext ); + ExtractFileExtension( source, ext, sizeof( source ) ); if ( !Q_stricmp( ext, "map" ) ) { StripExtension( source ); } - DefaultExtension( source, ".bsp" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); f = fopen( source, "rb" ); if ( f ) { size = Q_filelength( f ); diff --git a/tools/quake3/q3map2/bsp_scale.c b/tools/quake3/q3map2/bsp_scale.c index 57b14716..3dcf005d 100644 --- a/tools/quake3/q3map2/bsp_scale.c +++ b/tools/quake3/q3map2/bsp_scale.c @@ -62,7 +62,7 @@ int ScaleBSPMain( int argc, char **argv ){ /* do some path mangling */ strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); StripExtension( source ); - DefaultExtension( source, ".bsp" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", source ); @@ -134,7 +134,7 @@ int ScaleBSPMain( int argc, char **argv ){ /* write the bsp */ UnparseEntities(); StripExtension( source ); - DefaultExtension( source, "_s.bsp" ); + DefaultExtension( source, "_s.bsp", sizeof( source ) ); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); diff --git a/tools/quake3/q3map2/bspfile_abstract.c b/tools/quake3/q3map2/bspfile_abstract.c index 881ea2d5..ebe96269 100644 --- a/tools/quake3/q3map2/bspfile_abstract.c +++ b/tools/quake3/q3map2/bspfile_abstract.c @@ -391,7 +391,7 @@ void WriteBSPFile( const char *filename ){ /* make fake temp name so existing bsp file isn't damaged in case write process fails */ time( &tm ); - sprintf( tempname, "%s.%08X", filename, (int) tm ); + snprintf( tempname, sizeof( tempname ), "%s.%08X", filename, (int) tm ); /* byteswap, write the bsp, then swap back so it can be manipulated further */ SwapBSPFile(); @@ -626,26 +626,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 */ - sprintf( line, "\"%s\" \"%s\"\n", key, value ); - strcat( end, line ); + snprintf( line, sizeof( line ), "\"%s\" \"%s\"\n", key, value ); + 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/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 628bec2f..2f49670f 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" ); @@ -248,10 +248,10 @@ static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum ){ /* set bitmap filename */ if ( si->shaderImage->filename[ 0 ] != '*' ) { - strcpy( filename, si->shaderImage->filename ); + Q_strncpyz( filename, si->shaderImage->filename, sizeof( filename ) ); } else{ - sprintf( filename, "%s.tga", si->shader ); + snprintf( filename, sizeof( filename ), "%s.tga", si->shader ); } for ( c = filename; *c != '\0'; c++ ) if ( *c == '/' ) { @@ -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_bsp.c b/tools/quake3/q3map2/convert_bsp.c index ad434a01..971f6dbc 100644 --- a/tools/quake3/q3map2/convert_bsp.c +++ b/tools/quake3/q3map2/convert_bsp.c @@ -79,7 +79,7 @@ int ConvertBSPMain( int argc, char **argv ){ /* clean up map name */ strcpy( source, ExpandArg( argv[ i ] ) ); StripExtension( source ); - DefaultExtension( source, ".bsp" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); LoadShaderInfo(); @@ -100,7 +100,7 @@ int ConvertBSPMain( int argc, char **argv ){ /* write bsp */ StripExtension( source ); - DefaultExtension( source, "_c.bsp" ); + DefaultExtension( source, "_c.bsp", sizeof( source ) ); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); 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 b1236608..6e73c68c 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,9 +96,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", source ); diff --git a/tools/quake3/q3map2/fixaas.c b/tools/quake3/q3map2/fixaas.c index fc4eb94b..8af783c2 100644 --- a/tools/quake3/q3map2/fixaas.c +++ b/tools/quake3/q3map2/fixaas.c @@ -79,7 +79,7 @@ int FixAASMain( int argc, char **argv ){ /* do some path mangling */ strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); StripExtension( source ); - DefaultExtension( source, ".bsp" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* note it */ Sys_Printf( "--- FixAAS ---\n" ); diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index e54bef94..cf61dced 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/leakfile.c b/tools/quake3/q3map2/leakfile.c index be3f157f..2be60d06 100644 --- a/tools/quake3/q3map2/leakfile.c +++ b/tools/quake3/q3map2/leakfile.c @@ -76,7 +76,7 @@ xmlNodePtr LeakFile( tree_t *tree ){ // // write the points to the file // - sprintf( filename, "%s.lin", source ); + snprintf( filename, sizeof( filename ), "%s.lin", source ); linefile = fopen( filename, "w" ); if ( !linefile ) { Error( "Couldn't open %s\n", filename ); diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 2af9ac49..8535a76d 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1527,7 +1527,7 @@ void SetupGrid( void ){ int i, j; vec3_t maxs, oldGridSize; const char *value; - char temp[ 64 ]; + char temp[ 256 ]; /* don't do this if not grid lighting */ @@ -1573,7 +1573,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" ); } @@ -2255,12 +2255,12 @@ 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" ); - strcpy( mapSource, ExpandArg( argv[ i ] ) ); + DefaultExtension( source, ".bsp", sizeof( source ) ); + Q_strncpyz( mapSource, ExpandArg( argv[ i ] ), sizeof( mapSource ) ); StripExtension( mapSource ); - DefaultExtension( mapSource, ".map" ); + DefaultExtension( mapSource, ".map", sizeof( mapSource ) ); /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); 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 2079cbb0..d2d6909f 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 */ @@ -138,7 +138,7 @@ void ExportLightmaps( void ){ for ( i = 0, lightmap = bspLightBytes; lightmap < ( bspLightBytes + numBSPLightBytes ); i++, lightmap += ( game->lightmapSize * game->lightmapSize * 3 ) ) { /* write a tga image out */ - sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); + snprintf( filename, sizeof( filename ), "%s/lightmap_%04d.tga", dirname, i ); Sys_Printf( "Writing %s\n", filename ); WriteTGA24( filename, lightmap, game->lightmapSize, game->lightmapSize, qfalse ); } @@ -159,9 +159,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", source ); @@ -194,9 +194,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", 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 */ @@ -221,7 +221,7 @@ int ImportLightmapsMain( int argc, char **argv ){ for ( i = 0, lightmap = bspLightBytes; lightmap < ( bspLightBytes + numBSPLightBytes ); i++, lightmap += ( game->lightmapSize * game->lightmapSize * 3 ) ) { /* read a tga image */ - sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); + snprintf( filename, sizeof( filename ), "%s/lightmap_%04d.tga", dirname, i ); Sys_Printf( "Loading %s\n", filename ); buffer = NULL; len = vfsLoadFile( filename, (void*) &buffer, -1 ); @@ -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 ) ); @@ -2869,14 +2869,14 @@ void StoreSurfaceLightmaps( void ){ olm->extLightmapNum = numExtLightmaps; /* write lightmap */ - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); Sys_FPrintf( SYS_VRB, "\nwriting %s", filename ); WriteTGA24( filename, olm->bspLightBytes, olm->customWidth, olm->customHeight, qtrue ); numExtLightmaps++; /* write deluxemap */ if ( deluxemap ) { - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); Sys_FPrintf( SYS_VRB, "\nwriting %s", filename ); WriteTGA24( filename, olm->bspDirBytes, olm->customWidth, olm->customHeight, qtrue ); numExtLightmaps++; @@ -2896,7 +2896,7 @@ void StoreSurfaceLightmaps( void ){ for ( i = numExtLightmaps; i; i++ ) { /* determine if file exists */ - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP, dirname, i ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP, dirname, i ); if ( !FileExists( filename ) ) { break; } @@ -3042,11 +3042,11 @@ void StoreSurfaceLightmaps( void ){ /* surfaces with styled lightmaps and a style marker get a custom generated shader (fixme: make this work with external lightmaps) */ if ( olm != NULL && lm != NULL && lm->styles[ 1 ] != LS_NONE && game->load != LoadRBSPFile ) { //% info->si->styleMarker > 0 ) qboolean dfEqual; - char key[ 32 ], styleStage[ 512 ], styleStages[ 4096 ], rgbGen[ 128 ], alphaGen[ 128 ]; + char key[ 32 ], styleStage[ 512 ], styleStages[ 4096 ], rgbGen[ 256 ], alphaGen[ 256 ]; /* 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,15 +3071,15 @@ void StoreSurfaceLightmaps( void ){ /* lightmap name */ if ( lm->outLightmapNums[ lightmapNum ] == lm->outLightmapNums[ 0 ] ) { - strcpy( lightmapName, "$lightmap" ); + Q_strncpyz( lightmapName, "$lightmap", sizeof( lightmapName ) ); } else{ - sprintf( lightmapName, "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); + snprintf( lightmapName, sizeof( lightmapName ), "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); } /* 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"; @@ -3087,7 +3087,7 @@ void StoreSurfaceLightmaps( void ){ } rgbGen[ 0 ] = '\0'; if ( rgbGenValues[ style ][ 0 ] != '\0' ) { - sprintf( rgbGen, "\t\trgbGen %s // style %d\n", rgbGenValues[ style ], style ); + snprintf( rgbGen, sizeof( rgbGen ), "\t\trgbGen %s // style %d\n", rgbGenValues[ style ], style ); } else{ rgbGen[ 0 ] = '\0'; @@ -3095,11 +3095,11 @@ 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' ) { - sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); + snprintf( alphaGen, sizeof( alphaGen ), "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); } else{ alphaGen[ 0 ] = '\0'; @@ -3111,7 +3111,8 @@ void StoreSurfaceLightmaps( void ){ /* create additional stage */ if ( lmx == 0.0f && lmy == 0.0f ) { - sprintf( styleStage, "\t{\n" + snprintf( styleStage, sizeof( styleStage ), + "\t{\n" "\t\tmap %s\n" /* lightmap */ "\t\tblendFunc GL_SRC_ALPHA GL_ONE\n" "%s" /* depthFunc equal */ @@ -3126,7 +3127,8 @@ void StoreSurfaceLightmaps( void ){ } else { - sprintf( styleStage, "\t{\n" + snprintf( styleStage, sizeof( styleStage ), + "\t{\n" "\t\tmap %s\n" /* lightmap */ "\t\tblendFunc GL_SRC_ALPHA GL_ONE\n" "%s" /* depthFunc equal */ @@ -3144,7 +3146,7 @@ void StoreSurfaceLightmaps( void ){ } /* concatenate */ - strcat( styleStages, styleStage ); + strncat( styleStages, styleStage, sizeof( styleStages ) ); } /* create custom shader */ @@ -3171,7 +3173,7 @@ void StoreSurfaceLightmaps( void ){ olm = &outLightmaps[ lm->outLightmapNums[ 0 ] ]; /* do some name mangling */ - sprintf( lightmapName, "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); + snprintf( lightmapName, sizeof( lightmapName ), "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); /* create custom shader */ csi = CustomShader( info->si, "$lightmap", lightmapName ); diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index 3a92b6f5..1baeb100 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -46,7 +46,7 @@ vec_t Random( void ){ } -char *Q_strncpyz( char *dst, const char *src, size_t len ) { +/*char *Q_strncpyz( char *dst, const char *src, size_t len ) { if ( len == 0 ) { abort(); } @@ -54,7 +54,7 @@ char *Q_strncpyz( char *dst, const char *src, size_t len ) { strncpy( dst, src, len ); dst[ len - 1 ] = '\0'; return dst; -} +}*/ char *Q_strcat( char *dst, size_t dlen, const char *src ) { @@ -64,7 +64,8 @@ char *Q_strcat( char *dst, size_t dlen, const char *src ) { abort(); /* buffer overflow */ } - return Q_strncpyz( dst + n, src, dlen - n ); + Q_strncpyz( dst + n, src, dlen - n ); + return dst; } @@ -75,7 +76,8 @@ char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) { abort(); /* buffer overflow */ } - return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) ); + Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) ); + return dst; } diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index f491b7b7..f1a0170f 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -747,7 +747,7 @@ brush_t *FinishBrush( void ){ /* origin brushes are removed, but they set the rotation origin for the rest of the brushes in the entity. after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */ if ( buildBrush->compileFlags & C_ORIGIN ) { - char string[ 32 ]; + char string[ 64 ]; vec3_t origin; if ( numEntities == 1 ) { @@ -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 ) { @@ -1036,7 +1036,7 @@ static void ParseRawBrush( qboolean onlyLights ){ } /* set default flags and values */ - sprintf( shader, "textures/%s", name ); + snprintf( shader, sizeof( shader ), "textures/%s", name ); if ( onlyLights ) { si = &shaderInfo[ 0 ]; } @@ -1426,7 +1426,7 @@ void LoadEntityIndexMap( entity_t *e ){ Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename ); /* get index map file extension */ - ExtractFileExtension( indexMapFilename, ext ); + ExtractFileExtension( indexMapFilename, ext, sizeof( ext ) ); /* handle tga image */ if ( !Q_stricmp( ext, "tga" ) ) { @@ -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 */ @@ -1697,7 +1697,7 @@ static qboolean ParseMapEntity( qboolean onlyLights ){ value = ValueForKey( &entities[ 0 ], "_celshader" ); } if ( value[ 0 ] != '\0' ) { - sprintf( shader, "textures/%s", value ); + snprintf( shader, sizeof( shader ), "textures/%s", value ); celShader = ShaderInfoForShader( shader ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); } diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index a3028fdb..bda3833a 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 ); @@ -701,7 +701,7 @@ void AddTriangleModels( entity_t *e ){ value = ValueForKey( &entities[ 0 ], "_celshader" ); } if ( value[ 0 ] != '\0' ) { - sprintf( shader, "textures/%s", value ); + snprintf( shader, sizeof( shader ), "textures/%s", value ); celShader = ShaderInfoForShader( shader ); } else{ diff --git a/tools/quake3/q3map2/patch.c b/tools/quake3/q3map2/patch.c index fc2ef6c5..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]; @@ -355,7 +355,7 @@ void ParsePatch( qboolean onlyLights ){ pm->brushNum = entitySourceBrushes; /* set shader */ - sprintf( shader, "textures/%s", texture ); + snprintf( shader, sizeof( shader ), "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); /* set mesh */ diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index fb97a166..62955103 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -271,11 +271,11 @@ void AddHomeBasePath( char *path ){ basePaths[ i + 1 ] = basePaths[ i ]; /* concatenate home dir and path */ - sprintf( temp, "%s/%s", homePath, path ); + snprintf( temp, sizeof( temp ), "%s/%s", homePath, path ); /* add it to the list */ basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 ); - strcpy( basePaths[ 0 ], temp ); + Q_strncpyz( basePaths[ 0 ], temp, sizeof( basePaths ) ); CleanPath( basePaths[ 0 ] ); numBasePaths++; #endif @@ -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 ); @@ -451,7 +451,7 @@ void InitPaths( int *argc, char **argv ){ for ( i = 0; i < numBasePaths; i++ ) { /* create a full path and initialize it */ - sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] ); + snprintf( temp, sizeof( temp ), "%s/%s/", basePaths[ i ], gamePaths[ j ] ); //quick n dirty patch to enable vfs for quakelive if (strcmp(game->arg, "quakelive") == 0 ) { unz_GAME_QL = 1; diff --git a/tools/quake3/q3map2/prtfile.c b/tools/quake3/q3map2/prtfile.c index ce8da917..00fbf5e0 100644 --- a/tools/quake3/q3map2/prtfile.c +++ b/tools/quake3/q3map2/prtfile.c @@ -273,7 +273,7 @@ void WritePortalFile( tree_t *tree ){ Sys_FPrintf( SYS_VRB,"--- WritePortalFile ---\n" ); // write the file - sprintf( filename, "%s.prt", source ); + snprintf( filename, sizeof( filename ), "%s.prt", source ); Sys_Printf( "writing %s\n", filename ); pf = fopen( filename, "w" ); if ( !pf ) { diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 39959228..a7116f5d 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -67,8 +67,11 @@ extern int unz_GAME_QL; #include #endif -#ifdef WIN32 +#ifdef _WIN32 #include + #ifndef MAX_OS_PATH + #define MAX_OS_PATH MAX_PATH + #endif #endif @@ -111,7 +114,7 @@ extern int unz_GAME_QL; #endif #if 1 - #ifdef WIN32 + #ifdef _WIN32 #define Q_stricmp stricmp #define Q_strncasecmp strnicmp #else @@ -1462,7 +1465,10 @@ surfaceInfo_t; /* main.c */ vec_t Random( void ); -char *Q_strncpyz( char *dst, const char *src, size_t len ); +#ifndef Q_strncpyz +#define Q_strncpyz(_dst, _source, _len) do { strncpy((_dst), (_source), (_len) - 1); if ((_len) > 0) (_dst)[(_len) - 1] = 0; } while( 0 ) +#endif +//char *Q_strncpyz( char *dst, const char *src, size_t len ); char *Q_strcat( char *dst, size_t dlen, const char *src ); char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ); diff --git a/tools/quake3/q3map2/shaders.c b/tools/quake3/q3map2/shaders.c index 978856ef..9d9c516f 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -297,21 +297,21 @@ 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; } /* append ../scripts/q3map2_.shader */ - sprintf( mapShaderFile, "%s/../%s/q3map2_%s.shader", base, game->shaderPath, mapName ); + snprintf( mapShaderFile, sizeof( mapShaderFile ), "%s/../%s/q3map2_%s.shader", base, game->shaderPath, mapName ); Sys_FPrintf( SYS_VRB, "Map has shader script %s\n", mapShaderFile ); /* remove it */ @@ -423,7 +423,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* et: implicitMap */ if ( si->implicitMap == IM_OPAQUE ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted (implicitMap)\n" "\t{\n" "\t\tmap $lightmap\n" @@ -442,7 +443,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* et: implicitMask */ else if ( si->implicitMap == IM_MASKED ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted (implicitMask)\n" "\tcull none\n" "\t{\n" @@ -470,7 +472,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* et: implicitBlend */ else if ( si->implicitMap == IM_BLEND ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted (implicitBlend)\n" "\tcull none\n" "\t{\n" @@ -490,7 +493,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* default shader text */ else if ( srcShaderText == NULL ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted\n" "\t{\n" "\t\tmap $lightmap\n" @@ -521,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 */ @@ -533,7 +537,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ md5_finish( &mh, digest ); /* mangle hash into a shader name */ - sprintf( shader, "%s/%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", mapName, + snprintf( shader, sizeof( shader ), "%s/%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", mapName, digest[ 0 ], digest[ 1 ], digest[ 2 ], digest[ 3 ], digest[ 4 ], digest[ 5 ], digest[ 6 ], digest[ 7 ], digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ], digest[ 15 ] ); @@ -547,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 */ @@ -578,7 +582,7 @@ void EmitVertexRemapShader( char *from, char *to ){ } /* build value */ - sprintf( value, "%s;%s", from, to ); + snprintf( value, sizeof( value ), "%s;%s", from, to ); /* make md5 hash */ md5_init( &mh ); @@ -587,7 +591,7 @@ void EmitVertexRemapShader( char *from, char *to ){ /* make key (this is annoying, as vertexremapshader is precisely 17 characters, which is one too long, so we leave off the last byte of the md5 digest) */ - sprintf( key, "vertexremapshader%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", + snprintf( key, sizeof( key ), "vertexremapshader%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", digest[ 0 ], digest[ 1 ], digest[ 2 ], digest[ 3 ], digest[ 4 ], digest[ 5 ], digest[ 6 ], digest[ 7 ], digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ] ); /* no: digest[ 15 ] */ @@ -814,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 */ @@ -835,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 ); @@ -871,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 ] == '{' ) { @@ -937,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 ] ) ) @@ -954,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" ); @@ -1022,8 +1026,8 @@ static void ParseShaderFile( const char *filename ){ /* get an image */ GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) { - strcpy( si->lightImagePath, token ); - DefaultExtension( si->lightImagePath, ".tga" ); + Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); + DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); /* debug code */ //% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si->lightImagePath ); @@ -1129,7 +1133,7 @@ static void ParseShaderFile( const char *filename ){ GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] != '\0' ) { si->damageShader = safe_malloc( strlen( token ) + 1 ); - strcpy( si->damageShader, token ); + Q_strncpyz( si->damageShader, token, sizeof( si->damageShader ) ); } GetTokenAppend( shaderText, qfalse ); /* don't do anything with health */ } @@ -1139,10 +1143,10 @@ static void ParseShaderFile( const char *filename ){ si->implicitMap = IM_OPAQUE; GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } else{ - strcpy( si->implicitImagePath, token ); + Q_strncpyz( si->implicitImagePath, token, sizeof( si->implicitImagePath ) ); } } @@ -1150,10 +1154,10 @@ static void ParseShaderFile( const char *filename ){ si->implicitMap = IM_MASKED; GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } else{ - strcpy( si->implicitImagePath, token ); + Q_strncpyz( si->implicitImagePath, token, sizeof( si->implicitImagePath ) ); } } @@ -1161,10 +1165,10 @@ static void ParseShaderFile( const char *filename ){ si->implicitMap = IM_MASKED; GetTokenAppend( shaderText, qfalse ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } else{ - strcpy( si->implicitImagePath, token ); + Q_strncpyz( si->implicitImagePath, token, sizeof( si->implicitImagePath ) ); } } @@ -1176,22 +1180,22 @@ static void ParseShaderFile( const char *filename ){ /* qer_editorimage */ else if ( !Q_stricmp( token, "qer_editorImage" ) ) { GetTokenAppend( shaderText, qfalse ); - strcpy( si->editorImagePath, token ); - DefaultExtension( si->editorImagePath, ".tga" ); + Q_strncpyz( si->editorImagePath, token, sizeof( si->implicitImagePath ) ); + DefaultExtension( si->editorImagePath, ".tga", sizeof( si->editorImagePath ) ); } /* ydnar: q3map_normalimage (bumpmapping normal map) */ else if ( !Q_stricmp( token, "q3map_normalImage" ) ) { GetTokenAppend( shaderText, qfalse ); - strcpy( si->normalImagePath, token ); - DefaultExtension( si->normalImagePath, ".tga" ); + 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 ); - strcpy( si->lightImagePath, token ); - DefaultExtension( si->lightImagePath, ".tga" ); + Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); + DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); } /* ydnar: skyparms */ @@ -1201,11 +1205,11 @@ static void ParseShaderFile( const char *filename ){ /* ignore bogus paths */ if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) { - strcpy( si->skyParmsImageBase, token ); + Q_strncpyz( si->skyParmsImageBase, token, sizeof( si->skyParmsImageBase ) ); /* use top image as sky light image */ if ( si->lightImagePath[ 0 ] == '\0' ) { - sprintf( si->lightImagePath, "%s_up.tga", si->skyParmsImageBase ); + snprintf( si->lightImagePath, sizeof( si->implicitImagePath ), "%s_up.tga", si->skyParmsImageBase ); } } @@ -1312,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; @@ -1338,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 ); @@ -1372,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 ); @@ -1846,7 +1850,7 @@ static void ParseShaderFile( const char *filename ){ /* q3map_material (sof2) */ else if ( !Q_stricmp( token, "q3map_material" ) ) { GetTokenAppend( shaderText, qfalse ); - sprintf( temp, "*mat_%s", token ); + snprintf( temp, sizeof( temp ), "*mat_%s", token ); if ( ApplySurfaceParm( temp, &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) == qfalse ) { Sys_FPrintf( SYS_WRN, "WARNING: Unknown material \"%s\"\n", token ); } @@ -1924,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++; @@ -1950,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++; @@ -1988,14 +1992,14 @@ void LoadShaderInfo( void ){ numShaderFiles = 0; /* we can pile up several shader files, the one in baseq3 and ones in the mod dir or other spots */ - sprintf( filename, "%s/shaderlist.txt", game->shaderPath ); + snprintf( filename, sizeof( filename ), "%s/shaderlist.txt", game->shaderPath ); count = vfsGetFileCount( filename ); /* load them all */ for ( i = 0; i < count; i++ ) { /* load shader list */ - sprintf( filename, "%s/shaderlist.txt", game->shaderPath ); + snprintf( filename, sizeof( filename ), "%s/shaderlist.txt", game->shaderPath ); LoadScriptFile( filename, i ); /* parse it */ @@ -2015,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++; } } @@ -2024,7 +2028,7 @@ void LoadShaderInfo( void ){ /* parse the shader files */ for ( i = 0; i < numShaderFiles; i++ ) { - sprintf( filename, "%s/%s.shader", game->shaderPath, shaderFiles[ i ] ); + snprintf( filename, sizeof( filename ), "%s/%s.shader", game->shaderPath, shaderFiles[ i ] ); ParseShaderFile( filename ); free( shaderFiles[ i ] ); } diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index 3813cb1c..62ae4639 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -818,10 +818,10 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi /* make a shader name */ if ( minShaderIndex == maxShaderIndex ) { - sprintf( shader, "textures/%s_%d", im->shader, maxShaderIndex ); + snprintf( shader, sizeof( shader ), "textures/%s_%d", im->shader, maxShaderIndex ); } else{ - sprintf( shader, "textures/%s_%dto%d", im->shader, minShaderIndex, maxShaderIndex ); + snprintf( shader, sizeof( shader ), "textures/%s_%dto%d", im->shader, minShaderIndex, maxShaderIndex ); } /* get the shader */ @@ -917,17 +917,17 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin /* ydnar: sky hack/fix for GL_CLAMP borders on ati cards */ if ( skyFixHack && si->skyParmsImageBase[ 0 ] != '\0' ) { //% Sys_FPrintf( SYS_VRB, "Enabling sky hack for shader %s using env %s\n", si->shader, si->skyParmsImageBase ); - sprintf( tempShader, "%s_lf", si->skyParmsImageBase ); + snprintf( tempShader, sizeof( tempShader ), "%s_lf", si->skyParmsImageBase ); DrawSurfaceForShader( tempShader ); - sprintf( tempShader, "%s_rt", si->skyParmsImageBase ); + snprintf( tempShader, sizeof( tempShader ), "%s_rt", si->skyParmsImageBase ); DrawSurfaceForShader( tempShader ); - sprintf( tempShader, "%s_ft", si->skyParmsImageBase ); + snprintf( tempShader, sizeof( tempShader ), "%s_ft", si->skyParmsImageBase ); DrawSurfaceForShader( tempShader ); - sprintf( tempShader, "%s_bk", si->skyParmsImageBase ); + snprintf( tempShader, sizeof( tempShader ), "%s_bk", si->skyParmsImageBase ); DrawSurfaceForShader( tempShader ); - sprintf( tempShader, "%s_up", si->skyParmsImageBase ); + snprintf( tempShader, sizeof( tempShader ), "%s_up", si->skyParmsImageBase ); DrawSurfaceForShader( tempShader ); - sprintf( tempShader, "%s_dn", si->skyParmsImageBase ); + snprintf( tempShader, sizeof( tempShader ), "%s_dn", si->skyParmsImageBase ); DrawSurfaceForShader( tempShader ); } diff --git a/tools/quake3/q3map2/surface_extra.c b/tools/quake3/q3map2/surface_extra.c index c86058c6..a985999f 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/vis.c b/tools/quake3/q3map2/vis.c index 43c9ffaa..5cd13acc 100644 --- a/tools/quake3/q3map2/vis.c +++ b/tools/quake3/q3map2/vis.c @@ -1123,16 +1123,16 @@ int VisMain( int argc, char **argv ){ /* load the bsp */ - sprintf( source, "%s%s", inbase, ExpandArg( argv[ i ] ) ); + snprintf( source, sizeof( source ), "%s%s", inbase, ExpandArg( argv[ i ] ) ); StripExtension( source ); - strcat( source, ".bsp" ); + strncat( source, ".bsp", sizeof( source ) ); Sys_Printf( "Loading %s\n", source ); LoadBSPFile( source ); /* load the portal file */ - sprintf( portalfile, "%s%s", inbase, ExpandArg( argv[ i ] ) ); + snprintf( portalfile, sizeof( portalfile ), "%s%s", inbase, ExpandArg( argv[ i ] ) ); StripExtension( portalfile ); - strcat( portalfile, ".prt" ); + strncat( portalfile, ".prt", sizeof( portalfile ) ); Sys_Printf( "Loading %s\n", portalfile ); LoadPortals( portalfile ); diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index fecd7855..272e63f8 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; @@ -257,12 +257,12 @@ int EmitDrawNode_r( node_t *node ){ void SetModelNumbers( void ){ int i; int models; - char value[10]; + char value[16]; 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 ); } @@ -284,7 +284,7 @@ void SetLightStyles( void ){ const char *t; entity_t *e; epair_t *ep, *next; - char value[ 10 ]; + char value[ 16 ]; char lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ]; int lightStyles[ MAX_SWITCHED_LIGHTS ]; @@ -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 ); } } @@ -412,7 +412,7 @@ void EndBSPFile( void ){ WriteSurfaceExtraFile( source ); /* write the bsp */ - sprintf( path, "%s.bsp", source ); + snprintf( path, sizeof( path ), "%s.bsp", source ); Sys_Printf( "Writing %s\n", path ); WriteBSPFile( path ); } @@ -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 500333b6..ab543a15 100644 --- a/tools/urt/tools/quake3/q3map2/bsp.c +++ b/tools/urt/tools/quake3/q3map2/bsp.c @@ -54,7 +54,7 @@ static void SetCloneModelNumbers( void ){ int i, j; int models; - char modelValue[ 10 ]; + char modelValue[ 16 ]; const char *value, *value2, *value3; @@ -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!) */ @@ -352,7 +352,7 @@ void ProcessWorldModel( void ){ /* ydnar: fog hull */ value = ValueForKey( &entities[ 0 ], "_foghull" ); if ( value[ 0 ] != '\0' ) { - sprintf( shader, "textures/%s", value ); + snprintf( shader, sizeof( shader ), "textures/%s", value ); MakeFogHullSurfs( e, tree, shader ); } @@ -566,7 +566,7 @@ void OnlyEnts( void ){ /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); - sprintf( out, "%s.bsp", source ); + snprintf( out, sizeof( out ), "%s.bsp", source ); LoadBSPFile( out ); numEntities = 0; @@ -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" ); @@ -793,27 +793,27 @@ int BSPMain( int argc, char **argv ){ } /* copy source name */ - strcpy( source, ExpandArg( argv[ i ] ) ); + Q_strncpyz( source, ExpandArg( argv[ i ] ), sizeof( source ) ); StripExtension( source ); /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); /* delete portal, line and surface files */ - sprintf( path, "%s.prt", source ); + snprintf( path, sizeof( path ), "%s.prt", source ); remove( path ); - sprintf( path, "%s.lin", source ); + snprintf( path, sizeof( path ), "%s.lin", source ); remove( path ); //% sprintf( path, "%s.srf", source ); /* ydnar */ //% remove( path ); /* expand mapname */ - strcpy( name, ExpandArg( argv[ i ] ) ); + Q_strncpyz( name, ExpandArg( argv[ i ] ), sizeof( name ) ); if ( strcmp( name + strlen( name ) - 4, ".reg" ) ) { /* if we are doing a full map, delete the last saved region map */ - sprintf( path, "%s.reg", source ); + snprintf( path, sizeof( path ), "%s.reg", source ); remove( path ); - DefaultExtension( name, ".map" ); /* might be .reg */ + DefaultExtension( name, ".map", sizeof( name ) ); /* might be .reg */ } /* if onlyents, just grab the entites and resave */ diff --git a/tools/urt/tools/quake3/q3map2/bspfile_abstract.c b/tools/urt/tools/quake3/q3map2/bspfile_abstract.c index 39935e06..20da7910 100644 --- a/tools/urt/tools/quake3/q3map2/bspfile_abstract.c +++ b/tools/urt/tools/quake3/q3map2/bspfile_abstract.c @@ -373,7 +373,7 @@ void WriteBSPFile( const char *filename ){ /* make fake temp name so existing bsp file isn't damaged in case write process fails */ time( &tm ); - sprintf( tempname, "%s.%08X", filename, (int) tm ); + snprintf( tempname, sizeof( tempname ), "%s.%08X", filename, (int) tm ); /* byteswap, write the bsp, then swap back so it can be manipulated further */ SwapBSPFile(); @@ -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 */ - sprintf( line, "\"%s\" \"%s\"\n", key, value ); - strcat( end, line ); + snprintf( line, sizeof( line ), "\"%s\" \"%s\"\n", key, value ); + 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 628bec2f..2f49670f 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" ); @@ -248,10 +248,10 @@ static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum ){ /* set bitmap filename */ if ( si->shaderImage->filename[ 0 ] != '*' ) { - strcpy( filename, si->shaderImage->filename ); + Q_strncpyz( filename, si->shaderImage->filename, sizeof( filename ) ); } else{ - sprintf( filename, "%s.tga", si->shader ); + snprintf( filename, sizeof( filename ), "%s.tga", si->shader ); } for ( c = filename; *c != '\0'; c++ ) if ( *c == '/' ) { @@ -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/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 b1236608..6e73c68c 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,9 +96,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", source ); diff --git a/tools/urt/tools/quake3/q3map2/image.c b/tools/urt/tools/quake3/q3map2/image.c index 39a19854..e1b4e774 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/leakfile.c b/tools/urt/tools/quake3/q3map2/leakfile.c index be3f157f..2be60d06 100644 --- a/tools/urt/tools/quake3/q3map2/leakfile.c +++ b/tools/urt/tools/quake3/q3map2/leakfile.c @@ -76,7 +76,7 @@ xmlNodePtr LeakFile( tree_t *tree ){ // // write the points to the file // - sprintf( filename, "%s.lin", source ); + snprintf( filename, sizeof( filename ), "%s.lin", source ); linefile = fopen( filename, "w" ); if ( !linefile ) { Error( "Couldn't open %s\n", filename ); diff --git a/tools/urt/tools/quake3/q3map2/light.c b/tools/urt/tools/quake3/q3map2/light.c index 41bbc18e..c9abafe2 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" ); } @@ -1723,11 +1723,11 @@ void WriteRadbumpChunk(){ /* note it */ Sys_Printf( "--- WriteRadbumpChunk ---\n" ); - strcpy( dirname, source ); + Q_strncpyz( dirname, source, sizeof( dirname ) ); StripExtension( dirname ); //Check to see if the chunk exists - sprintf( filename, "%s.rad", dirname ); + snprintf( filename, sizeof( filename ), "%s.rad", dirname ); file = fopen( filename, "wb" ); @@ -2482,12 +2482,12 @@ 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" ); - strcpy( mapSource, ExpandArg( argv[ i ] ) ); + DefaultExtension( source, ".bsp", sizeof( source ) ); + Q_strncpyz( mapSource, ExpandArg( argv[ i ] ), sizeof( mapSource ) ); StripExtension( mapSource ); - DefaultExtension( mapSource, ".map" ); + DefaultExtension( mapSource, ".map", sizeof( mapSource ) ); /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); 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 f434cc41..bf921fd5 100644 --- a/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c @@ -120,7 +120,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 */ @@ -136,7 +136,7 @@ void ExportLightmaps( void ){ for ( i = 0, lightmap = bspLightBytes; lightmap < ( bspLightBytes + numBSPLightBytes ); i++, lightmap += ( game->lightmapSize * game->lightmapSize * 3 ) ) { /* write a tga image out */ - sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); + snprintf( filename, sizeof( filename ), "%s/lightmap_%04d.tga", dirname, i ); Sys_Printf( "Writing %s\n", filename ); WriteTGA24( filename, lightmap, game->lightmapSize, game->lightmapSize, qfalse ); } @@ -157,9 +157,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", source ); @@ -192,9 +192,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", source ); @@ -204,7 +204,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 */ @@ -219,7 +219,7 @@ int ImportLightmapsMain( int argc, char **argv ){ for ( i = 0, lightmap = bspLightBytes; lightmap < ( bspLightBytes + numBSPLightBytes ); i++, lightmap += ( game->lightmapSize * game->lightmapSize * 3 ) ) { /* read a tga image */ - sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); + snprintf( filename, sizeof( filename ), "%s/lightmap_%04d.tga", dirname, i ); Sys_Printf( "Loading %s\n", filename ); buffer = NULL; len = vfsLoadFile( filename, (void*) &buffer, -1 ); @@ -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 ) ); @@ -2813,12 +2813,12 @@ void StoreSurfaceLightmaps( void ){ olm->extLightmapNum = numExtLightmaps; if ( radbump ) { - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP_RAD, dirname, numExtLightmaps,radbumppass ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP_RAD, dirname, numExtLightmaps,radbumppass ); } else { - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); } Sys_FPrintf( SYS_VRB, "\nwriting %s", filename ); @@ -2828,7 +2828,7 @@ void StoreSurfaceLightmaps( void ){ /* write deluxemap */ if ( deluxemap ) { - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP, dirname, numExtLightmaps ); Sys_FPrintf( SYS_VRB, "\nwriting %s", filename ); WriteTGA24( filename, olm->bspDirBytes, olm->customWidth, olm->customHeight, qtrue ); numExtLightmaps++; @@ -2848,7 +2848,7 @@ void StoreSurfaceLightmaps( void ){ for ( i = numExtLightmaps; i; i++ ) { /* determine if file exists */ - sprintf( filename, "%s/" EXTERNAL_LIGHTMAP, dirname, i ); + snprintf( filename, sizeof( filename ), "%s/" EXTERNAL_LIGHTMAP, dirname, i ); if ( !FileExists( filename ) ) { break; } @@ -2995,11 +2995,11 @@ void StoreSurfaceLightmaps( void ){ /* surfaces with styled lightmaps and a style marker get a custom generated shader (fixme: make this work with external lightmaps) */ if ( olm != NULL && lm != NULL && lm->styles[ 1 ] != LS_NONE && game->load != LoadRBSPFile ) { //% info->si->styleMarker > 0 ) qboolean dfEqual; - char key[ 32 ], styleStage[ 512 ], styleStages[ 4096 ], rgbGen[ 128 ], alphaGen[ 128 ]; + char key[ 32 ], styleStage[ 512 ], styleStages[ 4096 ], rgbGen[ 256 ], alphaGen[ 256 ]; /* 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? */ @@ -3027,12 +3027,12 @@ void StoreSurfaceLightmaps( void ){ strcpy( lightmapName, "$lightmap" ); } else{ - sprintf( lightmapName, "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); + snprintf( lightmapName, sizeof( lightmapName ), "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); } /* 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"; @@ -3040,7 +3040,7 @@ void StoreSurfaceLightmaps( void ){ } rgbGen[ 0 ] = '\0'; if ( rgbGenValues[ style ][ 0 ] != '\0' ) { - sprintf( rgbGen, "\t\trgbGen %s // style %d\n", rgbGenValues[ style ], style ); + snprintf( rgbGen, sizeof( rgbGen ), "\t\trgbGen %s // style %d\n", rgbGenValues[ style ], style ); } else{ rgbGen[ 0 ] = '\0'; @@ -3048,11 +3048,11 @@ 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' ) { - sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); + snprintf( alphaGen, sizeof( alphaGen ), "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); } else{ alphaGen[ 0 ] = '\0'; @@ -3064,7 +3064,8 @@ void StoreSurfaceLightmaps( void ){ /* create additional stage */ if ( lmx == 0.0f && lmy == 0.0f ) { - sprintf( styleStage, "\t{\n" + snprintf( styleStage, sizeof( styleStage ), + "\t{\n" "\t\tmap %s\n" /* lightmap */ "\t\tblendFunc GL_SRC_ALPHA GL_ONE\n" "%s" /* depthFunc equal */ @@ -3079,7 +3080,8 @@ void StoreSurfaceLightmaps( void ){ } else { - sprintf( styleStage, "\t{\n" + snprintf( styleStage, sizeof( styleStage ), + "\t{\n" "\t\tmap %s\n" /* lightmap */ "\t\tblendFunc GL_SRC_ALPHA GL_ONE\n" "%s" /* depthFunc equal */ @@ -3097,7 +3099,7 @@ void StoreSurfaceLightmaps( void ){ } /* concatenate */ - strcat( styleStages, styleStage ); + strncat( styleStages, styleStage, sizeof( styleStages ) ); } /* create custom shader */ @@ -3124,7 +3126,7 @@ void StoreSurfaceLightmaps( void ){ olm = &outLightmaps[ lm->outLightmapNums[ 0 ] ]; /* do some name mangling */ - sprintf( lightmapName, "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); + snprintf( lightmapName, sizeof( lightmapName ), "maps/%s/" EXTERNAL_LIGHTMAP, mapName, olm->extLightmapNum ); /* create custom shader */ csi = CustomShader( info->si, "$lightmap", lightmapName ); diff --git a/tools/urt/tools/quake3/q3map2/main.c b/tools/urt/tools/quake3/q3map2/main.c index 924881b9..bfc0ef70 100644 --- a/tools/urt/tools/quake3/q3map2/main.c +++ b/tools/urt/tools/quake3/q3map2/main.c @@ -36,7 +36,7 @@ /* dependencies */ #include "q3map2.h" - +#include /* Random() @@ -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,12 +253,12 @@ int BSPInfo( int count, char **fileNames ){ Sys_Printf( "---------------------------------\n" ); /* mangle filename and get size */ - strcpy( source, fileNames[ i ] ); - ExtractFileExtension( source, ext ); + Q_strncpyz( source, fileNames[ i ], sizeof( source ) ); + ExtractFileExtension( source, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "map" ) ) { StripExtension( source ); } - DefaultExtension( source, ".bsp" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); f = fopen( source, "rb" ); if ( f ) { size = Q_filelength( f ); @@ -315,9 +315,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); /* load the bsp */ Sys_Printf( "Loading %s\n", 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,13 +383,13 @@ 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 */ UnparseEntities(); StripExtension( source ); - DefaultExtension( source, "_s.bsp" ); + DefaultExtension( source, "_s.bsp", sizeof( source ) ); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); @@ -443,9 +443,9 @@ 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" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); LoadShaderInfo(); @@ -466,7 +466,7 @@ int ConvertBSPMain( int argc, char **argv ){ /* write bsp */ StripExtension( source ); - DefaultExtension( source, "_c.bsp" ); + DefaultExtension( source, "_c.bsp", sizeof( source ) ); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); diff --git a/tools/urt/tools/quake3/q3map2/map.c b/tools/urt/tools/quake3/q3map2/map.c index 203b0b42..4913185b 100644 --- a/tools/urt/tools/quake3/q3map2/map.c +++ b/tools/urt/tools/quake3/q3map2/map.c @@ -587,7 +587,7 @@ brush_t *FinishBrush( void ){ /* origin brushes are removed, but they set the rotation origin for the rest of the brushes in the entity. after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */ if ( buildBrush->compileFlags & C_ORIGIN ) { - char string[ 32 ]; + char string[ 64 ]; vec3_t origin; if ( numEntities == 1 ) { @@ -599,7 +599,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 ); @@ -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 ) { @@ -876,7 +876,7 @@ static void ParseRawBrush( qboolean onlyLights ){ } /* set default flags and values */ - sprintf( shader, "textures/%s", name ); + snprintf( shader, sizeof( shader ), "textures/%s", name ); if ( onlyLights ) { si = &shaderInfo[ 0 ]; } @@ -1266,7 +1266,7 @@ void LoadEntityIndexMap( entity_t *e ){ Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename ); /* get index map file extension */ - ExtractFileExtension( indexMapFilename, ext ); + ExtractFileExtension( indexMapFilename, ext, sizeof( ext ) ); /* handle tga image */ if ( !Q_stricmp( ext, "tga" ) ) { @@ -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 */ @@ -1537,7 +1537,7 @@ static qboolean ParseMapEntity( qboolean onlyLights ){ value = ValueForKey( &entities[ 0 ], "_celshader" ); } if ( value[ 0 ] != '\0' ) { - sprintf( shader, "textures/%s", value ); + snprintf( shader, sizeof( shader ), "textures/%s", value ); celShader = ShaderInfoForShader( shader ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); } diff --git a/tools/urt/tools/quake3/q3map2/model.c b/tools/urt/tools/quake3/q3map2/model.c index 9361c65d..df2b10fe 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 ); @@ -768,7 +768,7 @@ void AddTriangleModels( entity_t *e ){ value = ValueForKey( &entities[ 0 ], "_celshader" ); } if ( value[ 0 ] != '\0' ) { - sprintf( shader, "textures/%s", value ); + snprintf( shader, sizeof( shader ), "textures/%s", value ); celShader = ShaderInfoForShader( shader ); } else{ diff --git a/tools/urt/tools/quake3/q3map2/patch.c b/tools/urt/tools/quake3/q3map2/patch.c index fc2ef6c5..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]; @@ -355,7 +355,7 @@ void ParsePatch( qboolean onlyLights ){ pm->brushNum = entitySourceBrushes; /* set shader */ - sprintf( shader, "textures/%s", texture ); + snprintf( shader, sizeof( shader ), "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); /* set mesh */ diff --git a/tools/urt/tools/quake3/q3map2/path_init.c b/tools/urt/tools/quake3/q3map2/path_init.c index 7f9eab11..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 ) { @@ -281,11 +281,11 @@ void AddHomeBasePath( char *path ){ basePaths[ i + 1 ] = basePaths[ i ]; /* concatenate home dir and path */ - sprintf( temp, "%s/%s", homePath, path ); + snprintf( temp, sizeof( temp ), "%s/%s", homePath, path ); /* add it to the list */ basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 ); - strcpy( basePaths[ 0 ], temp ); + Q_strncpyz( basePaths[ 0 ], temp, sizeof( basePaths ) ); CleanPath( basePaths[ 0 ] ); numBasePaths++; #endif @@ -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 ); @@ -449,7 +449,7 @@ void InitPaths( int *argc, char **argv ){ for ( i = 0; i < numBasePaths; i++ ) { /* create a full path and initialize it */ - sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] ); + snprintf( temp, sizeof( temp ), "%s/%s/", basePaths[ i ], gamePaths[ j ] ); vfsInitDirectory( temp ); } } diff --git a/tools/urt/tools/quake3/q3map2/prtfile.c b/tools/urt/tools/quake3/q3map2/prtfile.c index ce8da917..00fbf5e0 100644 --- a/tools/urt/tools/quake3/q3map2/prtfile.c +++ b/tools/urt/tools/quake3/q3map2/prtfile.c @@ -273,7 +273,7 @@ void WritePortalFile( tree_t *tree ){ Sys_FPrintf( SYS_VRB,"--- WritePortalFile ---\n" ); // write the file - sprintf( filename, "%s.prt", source ); + snprintf( filename, sizeof( filename ), "%s.prt", source ); Sys_Printf( "writing %s\n", filename ); pf = fopen( filename, "w" ); if ( !pf ) { diff --git a/tools/urt/tools/quake3/q3map2/q3map2.h b/tools/urt/tools/quake3/q3map2/q3map2.h index 8935ef2e..e952bdf7 100644 --- a/tools/urt/tools/quake3/q3map2/q3map2.h +++ b/tools/urt/tools/quake3/q3map2/q3map2.h @@ -57,9 +57,11 @@ #include #endif -#ifdef WIN32 +#ifdef _WIN32 #include - #define _CRT_SECURE_NO_WARNINGS + #ifndef MAX_OS_PATH + #define MAX_OS_PATH MAX_PATH + #endif #endif @@ -99,7 +101,7 @@ #endif #if 1 - #ifdef WIN32 + #ifdef _WIN32 #define Q_stricmp stricmp #define Q_strncasecmp strnicmp #else diff --git a/tools/urt/tools/quake3/q3map2/shaders.c b/tools/urt/tools/quake3/q3map2/shaders.c index 932c5d07..761bde5d 100644 --- a/tools/urt/tools/quake3/q3map2/shaders.c +++ b/tools/urt/tools/quake3/q3map2/shaders.c @@ -297,21 +297,21 @@ 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; } /* append ../scripts/q3map2_.shader */ - sprintf( mapShaderFile, "%s/../%s/q3map2_%s.shader", base, game->shaderPath, mapName ); + snprintf( mapShaderFile, sizeof( mapShaderFile ), "%s/../%s/q3map2_%s.shader", base, game->shaderPath, mapName ); Sys_FPrintf( SYS_VRB, "Map has shader script %s\n", mapShaderFile ); /* remove it */ @@ -422,7 +422,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* et: implicitMap */ if ( si->implicitMap == IM_OPAQUE ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted (implicitMap)\n" "\t{\n" "\t\tmap $lightmap\n" @@ -441,7 +442,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* et: implicitMask */ else if ( si->implicitMap == IM_MASKED ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted (implicitMask)\n" "\tcull none\n" "\t{\n" @@ -469,7 +471,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* et: implicitBlend */ else if ( si->implicitMap == IM_BLEND ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted (implicitBlend)\n" "\tcull none\n" "\t{\n" @@ -489,7 +492,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ /* default shader text */ else if ( srcShaderText == NULL ) { srcShaderText = temp; - sprintf( temp, "\n" + snprintf( temp, sizeof( temp ), + "\n" "{ // Q3Map2 defaulted\n" "\t{\n" "\t\tmap $lightmap\n" @@ -520,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 */ @@ -532,7 +536,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ md5_finish( &md5, digest ); /* mangle hash into a shader name */ - sprintf( shader, "%s/%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", mapName, + snprintf( shader, sizeof( shader ), "%s/%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", mapName, digest[ 0 ], digest[ 1 ], digest[ 2 ], digest[ 3 ], digest[ 4 ], digest[ 5 ], digest[ 6 ], digest[ 7 ], digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ], digest[ 15 ] ); @@ -546,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 */ @@ -577,7 +581,7 @@ void EmitVertexRemapShader( char *from, char *to ){ } /* build value */ - sprintf( value, "%s;%s", from, to ); + snprintf( value, sizeof( value ), "%s;%s", from, to ); /* make md5 hash */ md5_init( &md5 ); @@ -586,7 +590,7 @@ void EmitVertexRemapShader( char *from, char *to ){ /* make key (this is annoying, as vertexremapshader is precisely 17 characters, which is one too long, so we leave off the last byte of the md5 digest) */ - sprintf( key, "vertexremapshader%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", + snprintf( key, sizeof( key ), "vertexremapshader%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", digest[ 0 ], digest[ 1 ], digest[ 2 ], digest[ 3 ], digest[ 4 ], digest[ 5 ], digest[ 6 ], digest[ 7 ], digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ] ); /* no: digest[ 15 ] */ @@ -818,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 */ @@ -839,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 ); @@ -857,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; @@ -875,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 ] == '{' ) { @@ -895,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 ); } } @@ -941,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 ] ) ) @@ -958,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" ); @@ -967,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, "{" ) ) { @@ -984,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, "}" ) ) { @@ -1001,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, "}" ) ) { @@ -1020,14 +1024,14 @@ 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 ] != '$' ) { - strcpy( si->lightImagePath, token ); - DefaultExtension( si->lightImagePath, ".tga" ); + Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); + DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); /* debug code */ //% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si->lightImagePath ); @@ -1044,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_FPrintf( SYS_WRN, "WARNING: Unknown surfaceparm: \"%s\"\n", token ); } @@ -1067,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; } @@ -1083,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 ) ) { @@ -1103,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 ); @@ -1124,51 +1128,51 @@ 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 ); - strcpy( si->damageShader, token ); + 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' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } else{ - strcpy( si->implicitImagePath, token ); + Q_strncpyz( si->implicitImagePath, token, sizeof( si->implicitImagePath ) ); } } else if ( !Q_stricmp( token, "implicitMask" ) ) { si->implicitMap = IM_MASKED; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } else{ - strcpy( si->implicitImagePath, token ); + Q_strncpyz( si->implicitImagePath, token, sizeof( si->implicitImagePath ) ); } } else if ( !Q_stricmp( token, "implicitBlend" ) ) { si->implicitMap = IM_MASKED; - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) { - sprintf( si->implicitImagePath, "%s.tga", si->shader ); + snprintf( si->implicitImagePath, sizeof( si->implicitImagePath ), "%s.tga", si->shader ); } else{ - strcpy( si->implicitImagePath, token ); + Q_strncpyz( si->implicitImagePath, token, sizeof( si->implicitImagePath ) ); } } @@ -1179,43 +1183,43 @@ static void ParseShaderFile( const char *filename ){ /* qer_editorimage */ else if ( !Q_stricmp( token, "qer_editorImage" ) ) { - GetTokenAppend( shaderText, qfalse ); - strcpy( si->editorImagePath, token ); - DefaultExtension( si->editorImagePath, ".tga" ); + 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 ); - strcpy( si->normalImagePath, token ); - DefaultExtension( si->normalImagePath, ".tga" ); + 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 ); - strcpy( si->lightImagePath, token ); - DefaultExtension( si->lightImagePath, ".tga" ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); + Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); + DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); } /* 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" ) ) { - strcpy( si->skyParmsImageBase, token ); + Q_strncpyz( si->skyParmsImageBase, token, sizeof( si->skyParmsImageBase ) ); /* use top image as sky light image */ if ( si->lightImagePath[ 0 ] == '\0' ) { - sprintf( si->lightImagePath, "%s_up.tga", si->skyParmsImageBase ); + snprintf( si->lightImagePath, sizeof( si->lightImagePath ), "%s_up.tga", si->skyParmsImageBase ); } } /* skip rest of line */ - GetTokenAppend( shaderText, qfalse ); - GetTokenAppend( shaderText, qfalse ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); + GetTokenAppend( shaderText, qfalse, sizeof( shaderText ) ); } /* ----------------------------------------------------------------- @@ -1246,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; @@ -1278,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 ); } @@ -1306,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; @@ -1316,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; @@ -1341,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 ); } @@ -1375,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 */ @@ -1412,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; @@ -1432,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 ); } @@ -1496,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 */ @@ -1513,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; @@ -1522,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 ); } @@ -1533,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 ); @@ -1542,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 ); @@ -1551,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 ); @@ -1560,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 ); @@ -1569,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 ); } @@ -1604,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