From 88cd7e3232e59a8516a065e3f1ce42b27bc9a17e Mon Sep 17 00:00:00 2001 From: sezero Date: Tue, 27 Dec 2011 10:50:42 +0000 Subject: [PATCH] changed many sprintf() calls into q_snprintf(). git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@557 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Quake/common.c | 6 +++--- quakespasm/Quake/console.c | 6 +++--- quakespasm/Quake/gl_draw.c | 2 +- quakespasm/Quake/gl_model.c | 30 +++++++++++++++--------------- quakespasm/Quake/gl_rmisc.c | 2 +- quakespasm/Quake/gl_screen.c | 6 +++--- quakespasm/Quake/gl_sky.c | 6 +++--- quakespasm/Quake/gl_texmgr.c | 4 ++-- quakespasm/Quake/host_cmd.c | 18 +++++++++--------- quakespasm/Quake/image.c | 6 +++--- quakespasm/Quake/menu.c | 2 +- quakespasm/Quake/r_part.c | 2 +- quakespasm/Quake/sv_main.c | 4 ++-- 13 files changed, 47 insertions(+), 47 deletions(-) diff --git a/quakespasm/Quake/common.c b/quakespasm/Quake/common.c index 71ef7624..96c01eb9 100644 --- a/quakespasm/Quake/common.c +++ b/quakespasm/Quake/common.c @@ -1453,7 +1453,7 @@ void COM_WriteFile (const char *filename, const void *data, int len) Sys_mkdir (com_gamedir); //johnfitz -- if we've switched to a nonexistant gamedir, create it now so we don't crash - sprintf (name, "%s/%s", com_gamedir, filename); + q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, filename); handle = Sys_FileOpenWrite (name); if (handle == -1) @@ -1572,7 +1572,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file, continue; } - sprintf (netpath, "%s/%s",search->filename, filename); + q_snprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename); findtime = Sys_FileTime (netpath); if (findtime == -1) continue; @@ -1887,7 +1887,7 @@ void COM_AddGameDirectory (const char *dir) // add any pak files in the format pak0.pak pak1.pak, ... for (i = 0; ; i++) { - sprintf (pakfile, "%s/pak%i.pak", dir, i); + q_snprintf (pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); pak = COM_LoadPackFile (pakfile); if (!pak) break; diff --git a/quakespasm/Quake/console.c b/quakespasm/Quake/console.c index d1f220a1..b4b62934 100644 --- a/quakespasm/Quake/console.c +++ b/quakespasm/Quake/console.c @@ -162,7 +162,7 @@ void Con_Dump_f (void) #if 1 //johnfitz -- there is a security risk in writing files with an arbitrary filename. so, //until stuffcmd is crippled to alleviate this risk, just force the default filename. - sprintf (name, "%s/condump.txt", com_gamedir); + q_snprintf (name, sizeof(name), "%s/condump.txt", com_gamedir); #else if (Cmd_Argc() > 2) { @@ -177,11 +177,11 @@ void Con_Dump_f (void) Con_Printf ("Relative pathnames are not allowed.\n"); return; } - sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1)); + q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1)); COM_DefaultExtension (name, ".txt", sizeof(name)); } else - sprintf (name, "%s/condump.txt", com_gamedir); + q_snprintf (name, sizeof(name), "%s/condump.txt", com_gamedir); #endif COM_CreatePath (name); diff --git a/quakespasm/Quake/gl_draw.c b/quakespasm/Quake/gl_draw.c index a1c9937c..2d4ce312 100644 --- a/quakespasm/Quake/gl_draw.c +++ b/quakespasm/Quake/gl_draw.c @@ -246,7 +246,7 @@ qpic_t *Draw_PicFromWad (const char *name) else { char texturename[64]; //johnfitz - sprintf (texturename, "%s:%s", WADFILENAME, name); //johnfitz + q_snprintf (texturename, sizeof(texturename), "%s:%s", WADFILENAME, name); //johnfitz offset = (src_offset_t)p - (src_offset_t)wad_base + sizeof(int)*2; //johnfitz diff --git a/quakespasm/Quake/gl_model.c b/quakespasm/Quake/gl_model.c index c6b4906e..8c8dab2f 100644 --- a/quakespasm/Quake/gl_model.c +++ b/quakespasm/Quake/gl_model.c @@ -443,11 +443,11 @@ void Mod_LoadTextures (lump_t *l) //external textures -- first look in "textures/mapname/" then look in "textures/" mark = Hunk_LowMark(); COM_StripExtension (loadmodel->name + 5, mapname, sizeof(mapname)); - sprintf (filename, "textures/%s/#%s", mapname, tx->name+1); //this also replaces the '*' with a '#' + q_snprintf (filename, sizeof(filename), "textures/%s/#%s", mapname, tx->name+1); //this also replaces the '*' with a '#' data = Image_LoadImage (filename, &fwidth, &fheight); if (!data) { - sprintf (filename, "textures/#%s", tx->name+1); + q_snprintf (filename, sizeof(filename), "textures/#%s", tx->name+1); data = Image_LoadImage (filename, &fwidth, &fheight); } @@ -460,7 +460,7 @@ void Mod_LoadTextures (lump_t *l) } else //use the texture from the bsp file { - sprintf (texturename, "%s:%s", loadmodel->name, tx->name); + q_snprintf (texturename, sizeof(texturename), "%s:%s", loadmodel->name, tx->name); offset = (src_offset_t)(mt+1) - (src_offset_t)mod_base; tx->gltexture = TexMgr_LoadImage (loadmodel, texturename, tx->width, tx->height, SRC_INDEXED, (byte *)(tx+1), loadmodel->name, offset, TEXPREF_NONE); @@ -469,7 +469,7 @@ void Mod_LoadTextures (lump_t *l) //now create the warpimage, using dummy data from the hunk to create the initial image Hunk_Alloc (gl_warpimagesize*gl_warpimagesize*4); //make sure hunk is big enough so we don't reach an illegal address Hunk_FreeToLowMark (mark); - sprintf (texturename, "%s_warp", texturename); + q_snprintf (texturename, sizeof(texturename), "%s_warp", texturename); tx->warpimage = TexMgr_LoadImage (loadmodel, texturename, gl_warpimagesize, gl_warpimagesize, SRC_RGBA, hunk_base, "", (src_offset_t)hunk_base, TEXPREF_NOPICMIP | TEXPREF_WARPIMAGE); tx->update_warp = true; @@ -479,11 +479,11 @@ void Mod_LoadTextures (lump_t *l) //external textures -- first look in "textures/mapname/" then look in "textures/" mark = Hunk_LowMark (); COM_StripExtension (loadmodel->name + 5, mapname, sizeof(mapname)); - sprintf (filename, "textures/%s/%s", mapname, tx->name); + q_snprintf (filename, sizeof(filename), "textures/%s/%s", mapname, tx->name); data = Image_LoadImage (filename, &fwidth, &fheight); if (!data) { - sprintf (filename, "textures/%s", tx->name); + q_snprintf (filename, sizeof(filename), "textures/%s", tx->name); data = Image_LoadImage (filename, &fwidth, &fheight); } @@ -495,10 +495,10 @@ void Mod_LoadTextures (lump_t *l) //now try to load glow/luma image from the same place Hunk_FreeToLowMark (mark); - sprintf (filename2, "%s_glow", filename); + q_snprintf (filename2, sizeof(filename2), "%s_glow", filename); data = Image_LoadImage (filename2, &fwidth, &fheight); if (!data) - sprintf (filename2, "%s_luma", filename); + q_snprintf (filename2, sizeof(filename2), "%s_luma", filename); data = Image_LoadImage (filename2, &fwidth, &fheight); if (data) @@ -507,13 +507,13 @@ void Mod_LoadTextures (lump_t *l) } else //use the texture from the bsp file { - sprintf (texturename, "%s:%s", loadmodel->name, tx->name); + q_snprintf (texturename, sizeof(texturename), "%s:%s", loadmodel->name, tx->name); offset = (src_offset_t)(mt+1) - (src_offset_t)mod_base; if (Mod_CheckFullbrights ((byte *)(tx+1), pixels)) { tx->gltexture = TexMgr_LoadImage (loadmodel, texturename, tx->width, tx->height, SRC_INDEXED, (byte *)(tx+1), loadmodel->name, offset, TEXPREF_MIPMAP | TEXPREF_NOBRIGHT); - sprintf (texturename, "%s:%s_glow", loadmodel->name, tx->name); + q_snprintf (texturename, sizeof(texturename), "%s:%s_glow", loadmodel->name, tx->name); tx->fullbright = TexMgr_LoadImage (loadmodel, texturename, tx->width, tx->height, SRC_INDEXED, (byte *)(tx+1), loadmodel->name, offset, TEXPREF_MIPMAP | TEXPREF_FULLBRIGHT); } @@ -1885,13 +1885,13 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype) memcpy (texels, (byte *)(pskintype + 1), size); //johnfitz -- rewritten - sprintf (name, "%s:frame%i", loadmodel->name, i); + q_snprintf (name, sizeof(name), "%s:frame%i", loadmodel->name, i); offset = (src_offset_t)(pskintype+1) - (src_offset_t)mod_base; if (Mod_CheckFullbrights ((byte *)(pskintype+1), size)) { pheader->gltextures[i][0] = TexMgr_LoadImage (loadmodel, name, pheader->skinwidth, pheader->skinheight, SRC_INDEXED, (byte *)(pskintype+1), loadmodel->name, offset, TEXPREF_PAD | TEXPREF_NOBRIGHT); - sprintf (fbr_mask_name, "%s:frame%i_glow", loadmodel->name, i); + q_snprintf (fbr_mask_name, sizeof(fbr_mask_name), "%s:frame%i_glow", loadmodel->name, i); pheader->fbtextures[i][0] = TexMgr_LoadImage (loadmodel, fbr_mask_name, pheader->skinwidth, pheader->skinheight, SRC_INDEXED, (byte *)(pskintype+1), loadmodel->name, offset, TEXPREF_PAD | TEXPREF_FULLBRIGHT); } @@ -1928,13 +1928,13 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype) } //johnfitz -- rewritten - sprintf (name, "%s:frame%i_%i", loadmodel->name, i,j); + q_snprintf (name, sizeof(name), "%s:frame%i_%i", loadmodel->name, i,j); offset = (src_offset_t)(pskintype) - (src_offset_t)mod_base; //johnfitz if (Mod_CheckFullbrights ((byte *)(pskintype), size)) { pheader->gltextures[i][j&3] = TexMgr_LoadImage (loadmodel, name, pheader->skinwidth, pheader->skinheight, SRC_INDEXED, (byte *)(pskintype), loadmodel->name, offset, TEXPREF_PAD | TEXPREF_NOBRIGHT); - sprintf (fbr_mask_name, "%s:frame%i_%i_glow", loadmodel->name, i,j); + q_snprintf (fbr_mask_name, sizeof(fbr_mask_name), "%s:frame%i_%i_glow", loadmodel->name, i,j); pheader->fbtextures[i][j&3] = TexMgr_LoadImage (loadmodel, fbr_mask_name, pheader->skinwidth, pheader->skinheight, SRC_INDEXED, (byte *)(pskintype), loadmodel->name, offset, TEXPREF_PAD | TEXPREF_FULLBRIGHT); } @@ -2265,7 +2265,7 @@ void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int framenum) pspriteframe->tmax = (float)height/(float)TexMgr_PadConditional(height); //johnfitz - sprintf (name, "%s:frame%i", loadmodel->name, framenum); + q_snprintf (name, sizeof(name), "%s:frame%i", loadmodel->name, framenum); offset = (src_offset_t)(pinframe+1) - (src_offset_t)mod_base; //johnfitz pspriteframe->gltexture = TexMgr_LoadImage (loadmodel, name, width, height, SRC_INDEXED, diff --git a/quakespasm/Quake/gl_rmisc.c b/quakespasm/Quake/gl_rmisc.c index e6595310..c9d70b7d 100644 --- a/quakespasm/Quake/gl_rmisc.c +++ b/quakespasm/Quake/gl_rmisc.c @@ -305,7 +305,7 @@ void R_TranslateNewPlayerSkin (int playernum) pixels = (byte *)paliashdr + paliashdr->texels[skinnum]; // This is not a persistent place! //upload new image - sprintf(name, "player_%i", playernum); + q_snprintf(name, sizeof(name), "player_%i", playernum); playertextures[playernum] = TexMgr_LoadImage (currententity->model, name, paliashdr->skinwidth, paliashdr->skinheight, SRC_INDEXED, pixels, paliashdr->gltextures[skinnum][0]->source_file, paliashdr->gltextures[skinnum][0]->source_offset, TEXPREF_PAD | TEXPREF_OVERWRITE); diff --git a/quakespasm/Quake/gl_screen.c b/quakespasm/Quake/gl_screen.c index 72e05c9c..ff720931 100644 --- a/quakespasm/Quake/gl_screen.c +++ b/quakespasm/Quake/gl_screen.c @@ -451,7 +451,7 @@ SCR_DrawClock -- johnfitz */ void SCR_DrawClock (void) { - char str[9]; + char str[12]; if (scr_clock.value == 1) { @@ -738,8 +738,8 @@ void SCR_ScreenShot_f (void) // find a file name to save it to for (i=0; i<10000; i++) { - sprintf (tganame, "spasm%04i.tga", i); // "fitz%04i.tga" - sprintf (checkname, "%s/%s", com_gamedir, tganame); + q_snprintf (tganame, sizeof(tganame), "spasm%04i.tga", i); // "fitz%04i.tga" + q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, tganame); if (Sys_FileTime(checkname) == -1) break; // file doesn't exist } diff --git a/quakespasm/Quake/gl_sky.c b/quakespasm/Quake/gl_sky.c index d56e3259..a01780c5 100644 --- a/quakespasm/Quake/gl_sky.c +++ b/quakespasm/Quake/gl_sky.c @@ -105,7 +105,7 @@ void Sky_LoadTexture (texture_t *mt) for (j=0 ; j<128 ; j++) back_data[(i*128) + j] = src[i*256 + j + 128]; - sprintf(texturename, "%s:%s_back", loadmodel->name, mt->name); + q_snprintf(texturename, sizeof(texturename), "%s:%s_back", loadmodel->name, mt->name); solidskytexture = TexMgr_LoadImage (loadmodel, texturename, 128, 128, SRC_INDEXED, back_data, "", (src_offset_t)back_data, TEXPREF_NONE); // extract front layer and upload @@ -117,7 +117,7 @@ void Sky_LoadTexture (texture_t *mt) front_data[(i*128) + j] = 255; } - sprintf(texturename, "%s:%s_front", loadmodel->name, mt->name); + q_snprintf(texturename, sizeof(texturename), "%s:%s_front", loadmodel->name, mt->name); alphaskytexture = TexMgr_LoadImage (loadmodel, texturename, 128, 128, SRC_INDEXED, front_data, "", (src_offset_t)front_data, TEXPREF_ALPHA); // calculate r_fastsky color based on average of all opaque foreground colors @@ -175,7 +175,7 @@ void Sky_LoadSkyBox (const char *name) for (i=0; i<6; i++) { mark = Hunk_LowMark (); - sprintf (filename, "gfx/env/%s%s", name, suf[i]); + q_snprintf (filename, sizeof(filename), "gfx/env/%s%s", name, suf[i]); data = Image_LoadImage (filename, &width, &height); if (data) { diff --git a/quakespasm/Quake/gl_texmgr.c b/quakespasm/Quake/gl_texmgr.c index a84cde38..bb46e65a 100644 --- a/quakespasm/Quake/gl_texmgr.c +++ b/quakespasm/Quake/gl_texmgr.c @@ -230,7 +230,7 @@ void TexMgr_Imagedump_f (void) char *c; //create directory - sprintf(dirname, "%s/imagedump", com_gamedir); + q_snprintf(dirname, sizeof(dirname), "%s/imagedump", com_gamedir); Sys_mkdir (dirname); //loop through textures @@ -240,7 +240,7 @@ void TexMgr_Imagedump_f (void) while ( (c = strchr(tempname, ':')) ) *c = '_'; while ( (c = strchr(tempname, '/')) ) *c = '_'; while ( (c = strchr(tempname, '*')) ) *c = '_'; - sprintf(tganame, "imagedump/%s.tga", tempname); + q_snprintf(tganame, sizeof(tganame), "imagedump/%s.tga", tempname); GL_Bind (glt); if (glt->flags & TEXPREF_ALPHA) diff --git a/quakespasm/Quake/host_cmd.c b/quakespasm/Quake/host_cmd.c index d58ccc18..7e673458 100644 --- a/quakespasm/Quake/host_cmd.c +++ b/quakespasm/Quake/host_cmd.c @@ -189,7 +189,7 @@ void Host_Game_f (void) //Load the paks if any are found: for (i = 0; ; i++) { - sprintf (pakfile, "%s/pak%i.pak", com_gamedir, i); + q_snprintf (pakfile, sizeof(pakfile), "%s/pak%i.pak", com_gamedir, i); pak = COM_LoadPackFile (pakfile); if (!pak) break; @@ -278,13 +278,13 @@ void ExtraMaps_Init (void) // we don't want to list the maps in id1 pakfiles, // because these are not "add-on" levels - sprintf (ignorepakdir, "/%s/", GAMENAME); + q_snprintf (ignorepakdir, sizeof(ignorepakdir), "/%s/", GAMENAME); for (search = com_searchpaths; search; search = search->next) { if (*search->filename) //directory { - sprintf (filestring,"%s/maps/",search->filename); + q_snprintf (filestring, sizeof(filestring), "%s/maps/", search->filename); dir_p = opendir(filestring); if (dir_p == NULL) continue; @@ -411,9 +411,9 @@ void Modlist_Init (void) i = COM_CheckParm ("-basedir"); if (i && i < com_argc-1) - sprintf (dir_string, "%s/", com_argv[i+1]); + q_snprintf (dir_string, sizeof(dir_string), "%s/", com_argv[i+1]); else - sprintf (dir_string, "%s/", host_parms->basedir); + q_snprintf (dir_string, sizeof(dir_string), "%s/", host_parms->basedir); dir_p = opendir(dir_string); if (dir_p == NULL) @@ -423,7 +423,7 @@ void Modlist_Init (void) { if ((strcmp(dir_t->d_name, ".") == 0) || (strcmp(dir_t->d_name, "..") == 0)) continue; - sprintf(mod_dir_string, "%s%s/", dir_string, dir_t->d_name); + q_snprintf(mod_dir_string, sizeof(mod_dir_string), "%s%s/", dir_string, dir_t->d_name); mod_dir_p = opendir(mod_dir_string); if (mod_dir_p == NULL) continue; @@ -885,7 +885,7 @@ void Host_Changelevel_f (void) } //johnfitz -- check for client having map before anything else - sprintf (level, "maps/%s.bsp", Cmd_Argv(1)); + q_snprintf (level, sizeof(level), "maps/%s.bsp", Cmd_Argv(1)); if (COM_OpenFile (level, &i, NULL) == -1) Host_Error ("cannot find map %s", level); //johnfitz @@ -1047,7 +1047,7 @@ void Host_Savegame_f (void) } } - sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1)); + q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1)); COM_DefaultExtension (name, ".sav", sizeof(name)); Con_Printf ("Saving game to %s...\n", name); @@ -1119,7 +1119,7 @@ void Host_Loadgame_f (void) cls.demonum = -1; // stop demo loop in case this fails - sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1)); + q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1)); COM_DefaultExtension (name, ".sav", sizeof(name)); // we can't call SCR_BeginLoadingPlaque, because too much stack space has diff --git a/quakespasm/Quake/image.c b/quakespasm/Quake/image.c index 0a8ade32..91c4046e 100644 --- a/quakespasm/Quake/image.c +++ b/quakespasm/Quake/image.c @@ -37,12 +37,12 @@ byte *Image_LoadImage (const char *name, int *width, int *height) { FILE *f; - sprintf (loadfilename, "%s.tga", name); + q_snprintf (loadfilename, sizeof(loadfilename), "%s.tga", name); COM_FOpenFile (loadfilename, &f, NULL); if (f) return Image_LoadTGA (f, width, height); - sprintf (loadfilename, "%s.pcx", name); + q_snprintf (loadfilename, sizeof(loadfilename), "%s.pcx", name); COM_FOpenFile (loadfilename, &f, NULL); if (f) return Image_LoadPCX (f, width, height); @@ -106,7 +106,7 @@ qboolean Image_WriteTGA (const char *name, byte *data, int width, int height, in byte header[TARGAHEADERSIZE]; Sys_mkdir (com_gamedir); //if we've switched to a nonexistant gamedir, create it now so we don't crash - sprintf (pathname, "%s/%s", com_gamedir, name); + q_snprintf (pathname, sizeof(pathname), "%s/%s", com_gamedir, name); handle = Sys_FileOpenWrite (pathname); if (handle == -1) return false; diff --git a/quakespasm/Quake/menu.c b/quakespasm/Quake/menu.c index 73cd2f74..1038a618 100644 --- a/quakespasm/Quake/menu.c +++ b/quakespasm/Quake/menu.c @@ -431,7 +431,7 @@ void M_ScanSaves (void) { strcpy (m_filenames[i], "--- UNUSED SLOT ---"); loadable[i] = false; - sprintf (name, "%s/s%i.sav", com_gamedir, i); + q_snprintf (name, sizeof(name), "%s/s%i.sav", com_gamedir, i); f = fopen (name, "r"); if (!f) continue; diff --git a/quakespasm/Quake/r_part.c b/quakespasm/Quake/r_part.c index a2e15dae..7365c62c 100644 --- a/quakespasm/Quake/r_part.c +++ b/quakespasm/Quake/r_part.c @@ -269,7 +269,7 @@ void R_ReadPointFile_f (void) particle_t *p; char name[MAX_OSPATH]; - sprintf (name,"maps/%s.pts", sv.name); + q_snprintf (name, sizeof(name), "maps/%s.pts", sv.name); COM_FOpenFile (name, &f, NULL); if (!f) diff --git a/quakespasm/Quake/sv_main.c b/quakespasm/Quake/sv_main.c index c445cac3..a2c3acc8 100644 --- a/quakespasm/Quake/sv_main.c +++ b/quakespasm/Quake/sv_main.c @@ -1354,8 +1354,8 @@ void SV_SpawnServer (const char *server) sv.time = 1.0; - strcpy (sv.name, server); - sprintf (sv.modelname,"maps/%s.bsp", server); + strncpy (sv.name, server, sizeof(sv.name) - 1); + q_snprintf (sv.modelname, sizeof(sv.modelname), "maps/%s.bsp", server); sv.worldmodel = Mod_ForName (sv.modelname, false); if (!sv.worldmodel) {