diff --git a/contrib/bkgrnd2d/dialog.cpp b/contrib/bkgrnd2d/dialog.cpp index 84c62f7d..65ff8eee 100644 --- a/contrib/bkgrnd2d/dialog.cpp +++ b/contrib/bkgrnd2d/dialog.cpp @@ -169,7 +169,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/DBrush.cpp b/contrib/bobtoolz/DBrush.cpp index 3e54e797..a11908bf 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], diff --git a/contrib/bobtoolz/DTrainDrawer.cpp b/contrib/bobtoolz/DTrainDrawer.cpp index 51f7da44..da38ffba 100644 --- a/contrib/bobtoolz/DTrainDrawer.cpp +++ b/contrib/bobtoolz/DTrainDrawer.cpp @@ -235,7 +235,7 @@ void DTrainDrawer::BuildPaths() { AddSplineControl( control, pSP ); for ( int j = 2;; j++ ) { - char buffer[16]; + char buffer[32]; sprintf( buffer, "control%i", j ); e.SpawnString( buffer, NULL, &control ); diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp index 11c2e146..cb3248b7 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp @@ -154,7 +154,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 ); diff --git a/contrib/camera/funchandlers.cpp b/contrib/camera/funchandlers.cpp index a4a0aa70..337c8945 100644 --- a/contrib/camera/funchandlers.cpp +++ b/contrib/camera/funchandlers.cpp @@ -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 ); } @@ -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/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/gendlgs.cpp b/contrib/gtkgensurf/gendlgs.cpp index 372cdabb..0bf7ea7a 100644 --- a/contrib/gtkgensurf/gendlgs.cpp +++ b/contrib/gtkgensurf/gendlgs.cpp @@ -280,32 +280,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 ); @@ -385,9 +385,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; @@ -400,13 +400,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 ); @@ -726,14 +726,14 @@ static void main_go( GtkWidget *widget, gpointer data ){ ReadDlgValues( current_tab ); if ( NH < 1 || NH > MAX_ROWS ) { - sprintf( Text, "The number of divisions must be > 0 and no greater than %d.", MAX_ROWS ); + sprintf( Text, _( "The number of divisions must be > 0 and no greater than %d." ), MAX_ROWS ); g_FuncTable.m_pfnMessageBox( g_pWnd, Text, "GenSurf", MB_ICONEXCLAMATION, NULL ); gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), EXTENTS_TAB ); return; } if ( NV < 1 || NV > MAX_ROWS ) { - sprintf( Text, "The number of divisions must be > 0 and no greater than %d.", MAX_ROWS ); + sprintf( Text, _( "The number of divisions must be > 0 and no greater than %d." ), MAX_ROWS ); g_FuncTable.m_pfnMessageBox( g_pWnd, Text, "GenSurf", MB_ICONEXCLAMATION, NULL ); gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), EXTENTS_TAB ); return; @@ -1005,7 +1005,7 @@ static void fix_freeall( GtkWidget *widget, gpointer data ){ } void vertex_selected(){ - char Text[32]; + char Text[64]; int k; SetupControls(); @@ -1031,9 +1031,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 ); + sprintf( 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++ ) diff --git a/contrib/gtkgensurf/genmap.cpp b/contrib/gtkgensurf/genmap.cpp index f4336982..7de00c4f 100644 --- a/contrib/gtkgensurf/genmap.cpp +++ b/contrib/gtkgensurf/genmap.cpp @@ -192,8 +192,8 @@ int MapPatches(){ NH_patch -= 2; NH_remain -= ( NH_patch - 1 ); if ( NH_remain < 0 ) { - sprintf( szOops,"Oops... screwed up with NH=%d",NH ); - g_FuncTable.m_pfnMessageBox( NULL,szOops,"Uh oh", 0, NULL ); + sprintf( szOops, "Oops... screwed up with NH=%d", NH ); + g_FuncTable.m_pfnMessageBox( NULL, szOops, "Uh oh", 0, NULL ); } NV_remain = NV + 1; j0 = 0; @@ -233,8 +233,8 @@ int MapPatches(){ NV_patch -= 2; NV_remain -= ( NV_patch - 1 ); if ( NV_remain < 0 ) { - sprintf( szOops,"Oops... screwed up with NV=%d",NV ); - g_FuncTable.m_pfnMessageBox( NULL,szOops,"Uh oh", 0, NULL ); + sprintf( szOops, "Oops... screwed up with NV=%d", NV ); + g_FuncTable.m_pfnMessageBox( NULL, szOops, "Uh oh", 0, NULL ); } p.width = NH_patch; diff --git a/contrib/gtkgensurf/gensurf.cpp b/contrib/gtkgensurf/gensurf.cpp index d7dd17fd..fc0eedb8 100644 --- a/contrib/gtkgensurf/gensurf.cpp +++ b/contrib/gtkgensurf/gensurf.cpp @@ -423,7 +423,7 @@ 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 ); @@ -437,8 +437,8 @@ void SaveSetup( GtkWidget *parent ){ 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 ); + sprintf( 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 ); } } diff --git a/contrib/prtview/prtview.cpp b/contrib/prtview/prtview.cpp index 79b34fee..79eff190 100644 --- a/contrib/prtview/prtview.cpp +++ b/contrib/prtview/prtview.cpp @@ -349,10 +349,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 ); diff --git a/libs/splines/util_str.cpp b/libs/splines/util_str.cpp index 07768693..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 ); diff --git a/plugins/eclassfgd/plugin.cpp b/plugins/eclassfgd/plugin.cpp index a34dfeae..35a50077 100644 --- a/plugins/eclassfgd/plugin.cpp +++ b/plugins/eclassfgd/plugin.cpp @@ -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. @@ -596,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 ); } } } diff --git a/plugins/mapxml/xmlwrite.cpp b/plugins/mapxml/xmlwrite.cpp index 10052ee2..583dc6f2 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,15 +62,15 @@ 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 ); } } @@ -84,7 +84,7 @@ void Patch_XMLWrite( patchMesh_t *pPatch, xmlNodePtr surface ){ } 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 ); } } @@ -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 ); } } diff --git a/plugins/model/cpicosurface.cpp b/plugins/model/cpicosurface.cpp index 7aed8c08..25c26908 100644 --- a/plugins/model/cpicosurface.cpp +++ b/plugins/model/cpicosurface.cpp @@ -38,6 +38,8 @@ CPicoSurface::CPicoSurface( picoSurface_t *pSurface ){ // directory as a fall-back. This is a hack for malformed models. if ( m_shader->IsDefault() ) { + Sys_Printf( "WARNING: Failed to load shader %s for %s\n", m_shader->getName(), m_pSurface->model->name ); + gchar *dir = g_path_get_dirname( m_pSurface->model->name ); gchar *skin = g_strdup_printf( "%s/skin.tga", dir ); diff --git a/plugins/shaders/shaders.cpp b/plugins/shaders/shaders.cpp index b381287a..f323294a 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; } diff --git a/plugins/surface_idtech2/surfaceflags.cpp b/plugins/surface_idtech2/surfaceflags.cpp index 49e6c61c..e16ec308 100644 --- a/plugins/surface_idtech2/surfaceflags.cpp +++ b/plugins/surface_idtech2/surfaceflags.cpp @@ -86,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; @@ -301,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 ); @@ -333,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 ); @@ -391,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 ); g_signal_connect( content_buttons[i], "toggled", G_CALLBACK( on_content_button_toggled ), GINT_TO_POINTER( 1 << i ) ); diff --git a/plugins/vfspak/vfs.cpp b/plugins/vfspak/vfs.cpp index 4a7f11e7..d12b6240 100644 --- a/plugins/vfspak/vfs.cpp +++ b/plugins/vfspak/vfs.cpp @@ -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 ); diff --git a/plugins/vfsqlpk3/vfs.cpp b/plugins/vfsqlpk3/vfs.cpp index e0252ca4..fcaa17f3 100644 --- a/plugins/vfsqlpk3/vfs.cpp +++ b/plugins/vfsqlpk3/vfs.cpp @@ -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 ) { @@ -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 ); diff --git a/plugins/vfswad/vfs.cpp b/plugins/vfswad/vfs.cpp index 575b0684..e0d2a445 100644 --- a/plugins/vfswad/vfs.cpp +++ b/plugins/vfswad/vfs.cpp @@ -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); @@ -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 ); diff --git a/radiant/brush.cpp b/radiant/brush.cpp index 135fea94..7cef07d6 100644 --- a/radiant/brush.cpp +++ b/radiant/brush.cpp @@ -1550,7 +1550,7 @@ void CheckName( face_t *fa, char *pname, size_t length ){ 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 ); @@ -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 0f324475..0d12037d 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -118,7 +118,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 ) ) @@ -224,7 +224,7 @@ 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: diff --git a/radiant/eclass.cpp b/radiant/eclass.cpp index f3251dbc..926a025b 100644 --- a/radiant/eclass.cpp +++ b/radiant/eclass.cpp @@ -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 ) ); diff --git a/radiant/eclass_def.cpp b/radiant/eclass_def.cpp index 4fefb5b6..7d428d49 100644 --- a/radiant/eclass_def.cpp +++ b/radiant/eclass_def.cpp @@ -126,7 +126,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 ) ); diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 365a4361..02e8df9f 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -2739,7 +2739,7 @@ int DoBSInputDlg( const char *fields[5], float values[5] ){ gtk_box_pack_start( GTK_BOX( vbox ), entries[i], TRUE, TRUE, 0 ); gtk_widget_show( entries[i] ); - char buf[32]; + char buf[64]; sprintf( buf, "%f", values[i] ); gtk_entry_set_text( GTK_ENTRY( entries[i] ), buf ); } diff --git a/radiant/main.cpp b/radiant/main.cpp index 2779568c..f67602b0 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -773,7 +773,7 @@ int main( 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(); @@ -962,11 +962,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; @@ -1169,7 +1169,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 ) { @@ -1182,7 +1182,7 @@ void RunBsp( char *command ){ #endif #ifdef _WIN32 - sprintf( batpath, "%sqe3bsp.bat", temppath ); + 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 566efb78..9c1a8d4a 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -6242,7 +6242,7 @@ void MainFrame::OnMiscSelectentitycolor(){ } if ( inspector_mode == W_ENTITY && ( DoColor( COLOR_ENTITY ) ) ) { - char buffer[100]; + char buffer[256]; sprintf( 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/patchdialog.cpp b/radiant/patchdialog.cpp index ac16c9aa..20ad080d 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -291,7 +291,7 @@ void PatchDialog::BuildDialog(){ GtkWidget *dlg, *vbox, *vbox2, *hbox, *hbox2, *frame, *table, *label; GtkWidget *button, *entry, *spin, *combo; GtkAdjustment *adj; - char buf[32]; + char buf[64]; dlg = m_pWidget; @@ -465,7 +465,7 @@ void PatchDialog::BuildDialog(){ g_object_set_data( G_OBJECT( m_pWidget ), "hshift_entry", entry ); // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised // so we need to have at least one initialisation somewhere - sprintf( buf, "%g", l_pPIIncrement->shift[0] ); + snprintf( buf, sizeof( buf ), "%g", l_pPIIncrement->shift[0] ); gtk_entry_set_text( GTK_ENTRY( entry ), buf ); adj = gtk_adjustment_new( 0, -8192, 8192, 1, 1, 0 ); @@ -480,7 +480,7 @@ void PatchDialog::BuildDialog(){ entry = gtk_entry_new(); gtk_grid_attach( GTK_GRID( table ), entry, 0, 1, 1, 1 ); gtk_widget_show( entry ); - sprintf( buf, "%g", l_pPIIncrement->shift[1] ); + snprintf( buf, sizeof( buf ), "%g", l_pPIIncrement->shift[1] ); gtk_entry_set_text( GTK_ENTRY( entry ), buf ); adj = gtk_adjustment_new( 0, -8192, 8192, 1, 1, 0 ); @@ -495,7 +495,7 @@ void PatchDialog::BuildDialog(){ entry = gtk_entry_new(); gtk_grid_attach( GTK_GRID( table ), entry, 0, 2, 1, 1 ); gtk_widget_show( entry ); - sprintf( buf, "%g", l_pPIIncrement->scale[0] ); + snprintf( buf, sizeof( buf ), "%g", l_pPIIncrement->scale[0] ); gtk_entry_set_text( GTK_ENTRY( entry ), buf ); adj = gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ); @@ -510,7 +510,7 @@ void PatchDialog::BuildDialog(){ entry = gtk_entry_new(); gtk_grid_attach( GTK_GRID( table ), entry, 0, 3, 1, 1 ); gtk_widget_show( entry ); - sprintf( buf, "%g", l_pPIIncrement->scale[1] ); + snprintf( buf, sizeof( buf ), "%g", l_pPIIncrement->scale[1] ); gtk_entry_set_text( GTK_ENTRY( entry ), buf ); adj = gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ); @@ -525,7 +525,7 @@ void PatchDialog::BuildDialog(){ entry = gtk_entry_new(); gtk_grid_attach( GTK_GRID( table ), entry, 0, 4, 1, 1 ); gtk_widget_show( entry ); - sprintf( buf, "%g", l_pPIIncrement->rotate ); + snprintf( buf, sizeof( buf ), "%g", l_pPIIncrement->rotate ); gtk_entry_set_text( GTK_ENTRY( entry ), buf ); adj = gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ); // NOTE: Arnout - this really should be 360 but can't change it anymore as it could break existing maps diff --git a/radiant/pluginentities.cpp b/radiant/pluginentities.cpp index f32fb85c..2c384335 100644 --- a/radiant/pluginentities.cpp +++ b/radiant/pluginentities.cpp @@ -53,7 +53,7 @@ int QERApp_EClassScanDir( const 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/pmesh.cpp b/radiant/pmesh.cpp index 0bf9040a..e2fd95bd 100644 --- a/radiant/pmesh.cpp +++ b/radiant/pmesh.cpp @@ -4763,7 +4763,7 @@ void CheckName( patchMesh_t *p, char *pname, size_t length ){ // 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 ); Q_strncpyz( pname, SHADER_NOT_FOUND, length ); diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index b0029654..63e07699 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -307,7 +307,7 @@ void CXMLPropertyBag::GetPref( const char *name, int *pV, int V ){ } else { - char s[10]; + char s[12]; sprintf( s, "%d", V ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); @@ -347,7 +347,7 @@ void CXMLPropertyBag::GetPref( const char *name, float *pV, float V ){ } else { - char s[10]; + char s[64]; sprintf( s, "%f", V ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); @@ -364,7 +364,7 @@ void CXMLPropertyBag::GetPref( const char *name, float* pV, float* V ){ } else { - char s[128]; + char s[256]; sprintf( s, "%f %f %f", V[0], V[1], V[2] ); pNode = xmlNewChild( mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s ); xmlSetProp( pNode, (xmlChar *)"name", (xmlChar *)name ); @@ -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 @@ -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 ); @@ -2720,19 +2720,19 @@ void PrefsDlg::LoadTexdefPref( texdef_t* pTexdef, const char* pName ){ memset( pTexdef, 0, sizeof( texdef_t ) ); - sprintf( buffer, "%s%s", pName, TD_SCALE1_KEY ); + snprintf( buffer, sizeof( buffer ), "%s%s", pName, TD_SCALE1_KEY ); mLocalPrefs.GetPref( buffer, &pTexdef->scale[0], 0.5f ); - sprintf( buffer, "%s%s", pName, TD_SCALE2_KEY ); + snprintf( buffer, sizeof( buffer ), "%s%s", pName, TD_SCALE2_KEY ); mLocalPrefs.GetPref( buffer, &pTexdef->scale[1], 0.5f ); - sprintf( buffer, "%s%s", pName, TD_SHIFT1_KEY ); + snprintf( buffer, sizeof( buffer ), "%s%s", pName, TD_SHIFT1_KEY ); mLocalPrefs.GetPref( buffer, &pTexdef->shift[0], 8.f ); - sprintf( buffer, "%s%s", pName, TD_SHIFT2_KEY ); + snprintf( buffer, sizeof( buffer ), "%s%s", pName, TD_SHIFT2_KEY ); mLocalPrefs.GetPref( buffer, &pTexdef->shift[1], 8.f ); - sprintf( buffer, "%s%s", pName, TD_ROTATE_KEY ); + snprintf( buffer, sizeof( buffer ), "%s%s", pName, TD_ROTATE_KEY ); mLocalPrefs.GetPref( buffer, &pTexdef->rotate, 45 ); } diff --git a/radiant/profile.cpp b/radiant/profile.cpp index 2e391bdb..df645ce0 100644 --- a/radiant/profile.cpp +++ b/radiant/profile.cpp @@ -192,7 +192,7 @@ bool WINAPI profile_save_int( const char *filename, const char *section, const c } bool WINAPI profile_save_float( const char *filename, const char *section, const char *key, float value ){ - char buf[16]; + char buf[64]; sprintf( 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; diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index d779ecb5..c512ea67 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,7 +126,7 @@ 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; } @@ -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++; @@ -645,7 +645,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", @@ -662,7 +662,7 @@ bool QE_LoadProject( const char *projectfile ){ 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 @@ -1266,7 +1266,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 ); diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index d106e382..11d04c72 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -929,11 +929,8 @@ void SurfaceDlg::SetTexMods(){ } GtkAdjustment *adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); gtk_adjustment_set_step_increment( adjust, l_pIncrement->shift[0] ); - char buf[10]; // got into snprintf paranoia after BoundChecker detected a stack overrun -#if defined(_MSC_VER) && _MSC_VER<1900 && !(defined snprintf) -#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" ) ); @@ -946,7 +943,7 @@ void SurfaceDlg::SetTexMods(){ } adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); gtk_adjustment_set_step_increment( adjust, 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" ) ); @@ -955,7 +952,7 @@ void SurfaceDlg::SetTexMods(){ adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); gtk_adjustment_set_step_increment( adjust, 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" ) ); @@ -964,7 +961,7 @@ void SurfaceDlg::SetTexMods(){ adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); gtk_adjustment_set_step_increment( adjust, 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 .. @@ -974,7 +971,7 @@ void SurfaceDlg::SetTexMods(){ adjust = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON( spin ) ); gtk_adjustment_set_step_increment( adjust, 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; diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index e8a662c2..00c99b34 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -518,7 +518,7 @@ void BuildShaderList(){ bool found = false; // each token should be a shader filename - sprintf( dirstring, "%s.shader", token ); + snprintf( dirstring, sizeof( dirstring ), "%s.shader", token ); for ( tmp = l_shaderfiles; tmp != NULL; tmp = tmp->next ) { @@ -884,7 +884,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 ) @@ -894,7 +894,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; @@ -927,7 +927,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 ); @@ -943,7 +943,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 @@ -1158,7 +1158,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 ) { diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 6fc13fad..6d050ba8 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -423,7 +423,7 @@ void CreateEntityFromName( const char* name, const vec3_t origin ){ // prompt.GotoDlgCtrl( pWnd ); if ( DoLightIntensityDlg( &intensity ) == IDOK ) { g_PrefsDlg.m_iLastLightIntensity = intensity; - char buf[10]; + char buf[12]; sprintf( buf, "%d", intensity ); SetKeyValue( e, "light", buf ); } diff --git a/tools/quake3/common/aselib.c b/tools/quake3/common/aselib.c index 6f45c841..d23422fd 100644 --- a/tools/quake3/common/aselib.c +++ b/tools/quake3/common/aselib.c @@ -473,7 +473,7 @@ static void ASE_KeyMAP_DIFFUSE( const char *token ){ } 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 ); } } diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 046dda4f..349d9ac4 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -124,7 +124,7 @@ void ExpandWildcards( int *argc, char ***argv ){ 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 ); @@ -248,7 +248,7 @@ char *ExpandPath( const char *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; } diff --git a/tools/quake3/common/inout.c b/tools/quake3/common/inout.c index dc56376a..d0eaa871 100644 --- a/tools/quake3/common/inout.c +++ b/tools/quake3/common/inout.c @@ -150,7 +150,7 @@ 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 ) ; @@ -163,7 +163,7 @@ void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ){ 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 ); } @@ -211,7 +211,7 @@ void xml_Winding( char *msg, vec3_t p[], int numpoints, qboolean die ){ sprintf( 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; @@ -349,7 +349,7 @@ void Error( const char *error, ... ){ 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/vfs.c b/tools/quake3/common/vfs.c index 9f615c1d..5620501b 100644 --- a/tools/quake3/common/vfs.c +++ b/tools/quake3/common/vfs.c @@ -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 ); diff --git a/tools/quake3/q3data/3dslib.c b/tools/quake3/q3data/3dslib.c index 1ac390cf..f505d253 100644 --- a/tools/quake3/q3data/3dslib.c +++ b/tools/quake3/q3data/3dslib.c @@ -149,7 +149,7 @@ 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 ); } @@ -159,7 +159,7 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat } 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 ); } @@ -169,7 +169,7 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat } 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 ); } @@ -179,7 +179,7 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat } 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 ); } @@ -189,7 +189,7 @@ static void LoadMaterialList( FILE *fp, long thisChunkLen, _3DSMaterial_t *pMat } 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 ); } diff --git a/tools/quake3/q3data/video.c b/tools/quake3/q3data/video.c index 7fceb79c..1605881a 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" ); diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index ed758d6c..0ac29021 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -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; @@ -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; @@ -864,9 +864,9 @@ int BSPMain( int argc, char **argv ){ 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 ); @@ -875,7 +875,7 @@ int BSPMain( int argc, char **argv ){ 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", sizeof( name ) ); /* might be .reg */ } diff --git a/tools/quake3/q3map2/bspfile_abstract.c b/tools/quake3/q3map2/bspfile_abstract.c index a117c923..5ca0ecc5 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(); @@ -639,8 +639,8 @@ void UnparseEntities( void ){ 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 ); } diff --git a/tools/quake3/q3map2/convert_ase.c b/tools/quake3/q3map2/convert_ase.c index a2d6ad34..930452e2 100644 --- a/tools/quake3/q3map2/convert_ase.c +++ b/tools/quake3/q3map2/convert_ase.c @@ -251,7 +251,7 @@ static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum ){ 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 == '/' ) { 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 b3002282..79f16f08 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" ); } diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index 79e77186..01642716 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -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 ); } @@ -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 ); @@ -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,7 +3042,7 @@ 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 */ @@ -3074,7 +3074,7 @@ 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 */ @@ -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'; @@ -3099,7 +3099,7 @@ void StoreSurfaceLightmaps( void ){ 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/map.c b/tools/quake3/q3map2/map.c index 764cf944..fd8b1c74 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 ) { @@ -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 ]; } @@ -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 a6daedf0..3f703d4d 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -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..ba2ea8ba 100644 --- a/tools/quake3/q3map2/patch.c +++ b/tools/quake3/q3map2/patch.c @@ -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..2dd75cfb 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 @@ -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/shaders.c b/tools/quake3/q3map2/shaders.c index b7f46416..4d95a99a 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -311,7 +311,7 @@ void BeginMapShaderFile( const char *mapFile ){ } /* 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" @@ -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 ] ); @@ -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 ] */ @@ -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,21 +1180,21 @@ static void ParseShaderFile( const char *filename ){ /* qer_editorimage */ else if ( !Q_stricmp( token, "qer_editorImage" ) ) { GetTokenAppend( shaderText, qfalse ); - strcpy( si->editorImagePath, token ); + 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 ); + 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 ); + Q_strncpyz( si->lightImagePath, token, sizeof( si->lightImagePath ) ); DefaultExtension( si->lightImagePath, ".tga", sizeof( si->lightImagePath ) ); } @@ -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 ); } } @@ -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_Printf( "WARNING: Unknown material \"%s\"\n", token ); } @@ -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 */ @@ -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 061e8ab6..35270399 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/vis.c b/tools/quake3/q3map2/vis.c index e97144bc..075f37b3 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 8fd073cd..2b540110 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -257,7 +257,7 @@ 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++ ) { @@ -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 ]; @@ -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 ); } diff --git a/tools/urt/tools/quake3/q3map2/bsp.c b/tools/urt/tools/quake3/q3map2/bsp.c index 24c49420..d684bdcb 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; @@ -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; @@ -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 116f3d33..221e79c0 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(); @@ -621,7 +621,7 @@ void UnparseEntities( void ){ StripTrailing( value ); /* add to buffer */ - sprintf( line, "\"%s\" \"%s\"\n", key, value ); + snprintf( line, sizeof( line ), "\"%s\" \"%s\"\n", key, value ); strcat( end, line ); end += strlen( line ); } diff --git a/tools/urt/tools/quake3/q3map2/convert_ase.c b/tools/urt/tools/quake3/q3map2/convert_ase.c index 0bbb5816..53cbe85c 100644 --- a/tools/urt/tools/quake3/q3map2/convert_ase.c +++ b/tools/urt/tools/quake3/q3map2/convert_ase.c @@ -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" ); + strncat( base, ".bsp", sizeof( base ) ); /* open it */ f = fopen( name, "wb" ); 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 e4cf8aca..03bf40c0 100644 --- a/tools/urt/tools/quake3/q3map2/light.c +++ b/tools/urt/tools/quake3/q3map2/light.c @@ -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" ); @@ -2484,10 +2484,10 @@ int LightMain( int argc, char **argv ){ /* clean up map name */ strcpy( source, ExpandArg( argv[ i ] ) ); StripExtension( source ); - DefaultExtension( source, ".bsp" ); + DefaultExtension( source, ".bsp", sizeof( source ) ); strcpy( mapSource, ExpandArg( argv[ i ] ) ); 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/lightmaps_ydnar.c b/tools/urt/tools/quake3/q3map2/lightmaps_ydnar.c index ea276d2c..8ee307e8 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 ); } @@ -159,7 +159,7 @@ int ExportLightmapsMain( 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 ); @@ -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 ); @@ -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,7 +2995,7 @@ 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 */ @@ -3027,7 +3027,7 @@ 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 */ @@ -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'; @@ -3052,7 +3052,7 @@ void StoreSurfaceLightmaps( void ){ 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/map.c b/tools/urt/tools/quake3/q3map2/map.c index f087784d..8e185466 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 ); @@ -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" ) ) { @@ -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 f4413b4d..38003d4b 100644 --- a/tools/urt/tools/quake3/q3map2/model.c +++ b/tools/urt/tools/quake3/q3map2/model.c @@ -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..ba2ea8ba 100644 --- a/tools/urt/tools/quake3/q3map2/patch.c +++ b/tools/urt/tools/quake3/q3map2/patch.c @@ -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..19c8c782 100644 --- a/tools/urt/tools/quake3/q3map2/path_init.c +++ b/tools/urt/tools/quake3/q3map2/path_init.c @@ -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 @@ -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/shaders.c b/tools/urt/tools/quake3/q3map2/shaders.c index 863a59ef..c19399e5 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" @@ -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 ] ); @@ -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 ] */ @@ -1026,8 +1030,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 ); @@ -1133,7 +1137,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 */ } @@ -1143,10 +1147,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 ) ); } } @@ -1154,10 +1158,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 ) ); } } @@ -1165,10 +1169,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 ) ); } } @@ -1180,22 +1184,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->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" ); + 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 */ @@ -1205,11 +1209,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->lightImagePath ), "%s_up.tga", si->skyParmsImageBase ); } } @@ -1850,7 +1854,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_Printf( "WARNING: Unknown material \"%s\"\n", token ); } @@ -1994,14 +1998,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 */ @@ -2030,7 +2034,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/urt/tools/quake3/q3map2/surface.c b/tools/urt/tools/quake3/q3map2/surface.c index 32a5a9b8..1cc09ccd 100644 --- a/tools/urt/tools/quake3/q3map2/surface.c +++ b/tools/urt/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/urt/tools/quake3/q3map2/vis.c b/tools/urt/tools/quake3/q3map2/vis.c index adbefa4b..2eaf33d3 100644 --- a/tools/urt/tools/quake3/q3map2/vis.c +++ b/tools/urt/tools/quake3/q3map2/vis.c @@ -1129,16 +1129,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/urt/tools/quake3/q3map2/writebsp.c b/tools/urt/tools/quake3/q3map2/writebsp.c index 47758f5c..4d8e6380 100644 --- a/tools/urt/tools/quake3/q3map2/writebsp.c +++ b/tools/urt/tools/quake3/q3map2/writebsp.c @@ -260,7 +260,7 @@ 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++ ) { @@ -287,7 +287,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 ]; @@ -413,7 +413,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 ); }