From: havoc Date: Wed, 23 Nov 2005 02:54:50 +0000 (+0000) Subject: cleaned up many text buffer sizes throughout the engine, most now use MAX_INPUTLINE... X-Git-Tag: xonotic-v0.1.0preview~4468 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7403ba135fe27515470bfc6a7f8980869ccfee76;p=xonotic%2Fdarkplaces.git cleaned up many text buffer sizes throughout the engine, most now use MAX_INPUTLINE, some use MAX_QPATH, also cleaned up a lot of stuff that had buffer sizes in the code (now uses sizeof) increased MAX_INPUTLINE from 256 to 16384, so now console commandlines and many other things can be very large git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5816 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_demo.c b/cl_demo.c index 2ab796bc..3a655ea0 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -46,7 +46,7 @@ Called to play the next demo in the demo loop */ void CL_NextDemo (void) { - char str[1024]; + char str[MAX_INPUTLINE]; if (cls.demonum == -1) return; // don't play demos @@ -313,7 +313,7 @@ play [demoname] */ void CL_PlayDemo_f (void) { - char name[256]; + char name[MAX_QPATH]; int c; qboolean neg = false; diff --git a/cl_main.c b/cl_main.c index 13c04f1e..dd1effc6 100644 --- a/cl_main.c +++ b/cl_main.c @@ -1507,6 +1507,7 @@ void CL_Init (void) r_refdef.maxentities = MAX_EDICTS + 256 + 512; r_refdef.entities = (entity_render_t **)Mem_Alloc(cl_mempool, sizeof(entity_render_t *) * r_refdef.maxentities); // 256k drawqueue buffer + // TODO: make dynamic r_refdef.maxdrawqueuesize = 256 * 1024; r_refdef.drawqueue = (unsigned char *)Mem_Alloc(cl_mempool, r_refdef.maxdrawqueuesize); diff --git a/cl_parse.c b/cl_parse.c index f32d9b48..7223ce10 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -213,7 +213,7 @@ void CL_KeepaliveMessage (void) void CL_ParseEntityLump(char *entdata) { const char *data; - char key[128], value[4096]; + char key[128], value[MAX_INPUTLINE]; FOG_clear(); // LordHavoc: no fog until set // LordHavoc: default to the map's sky (q3 shader parsing sets this) R_SetSkyBox(cl.worldmodel->brush.skybox); diff --git a/cl_screen.c b/cl_screen.c index 9fc16596..fa9bff8e 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -162,7 +162,7 @@ CENTER PRINTING =============================================================================== */ -char scr_centerstring[1024]; +char scr_centerstring[MAX_INPUTLINE]; float scr_centertime_start; // for slow victory printing float scr_centertime_off; int scr_center_lines; @@ -1198,7 +1198,7 @@ envmapinfo[12] = static void R_Envmap_f (void) { int j, size; - char filename[256], basename[256]; + char filename[MAX_QPATH], basename[MAX_QPATH]; unsigned char *buffer1; unsigned char *buffer2; unsigned char *buffer3; diff --git a/cl_video.c b/cl_video.c index 1055cf00..84332390 100644 --- a/cl_video.c +++ b/cl_video.c @@ -266,7 +266,7 @@ void CL_VideoStop(void) static void CL_PlayVideo_f(void) { - char name[1024]; + char name[MAX_QPATH]; Host_StartVideo(); diff --git a/cmd.c b/cmd.c index 47892f9a..9a8a56da 100644 --- a/cmd.c +++ b/cmd.c @@ -22,6 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #define MAX_ALIAS_NAME 32 +// this is the largest script file that can be executed in one step +// LordHavoc: inreased this from 8192 to 32768 +#define CMDBUFSIZE 32768 +// maximum number of parameters to a command +#define MAX_ARGS 80 +// maximum tokenizable commandline length (counting NUL terminations) +#define CMD_TOKENIZELENGTH (MAX_INPUTLINE + 80) typedef struct cmdalias_s { @@ -36,7 +43,6 @@ static qboolean cmd_wait; static mempool_t *cmd_mempool; -#define CMD_TOKENIZELENGTH 4096 static char cmd_tokenizebuffer[CMD_TOKENIZELENGTH]; static int cmd_tokenizebufferpos = 0; @@ -64,9 +70,8 @@ static void Cmd_Wait_f (void) ============================================================================= */ - // LordHavoc: inreased this from 8192 to 32768 static sizebuf_t cmd_text; -static unsigned char cmd_text_buf[32768]; +static unsigned char cmd_text_buf[CMDBUFSIZE]; /* ============ @@ -135,11 +140,10 @@ Cbuf_Execute static void Cmd_PreprocessString( const char *intext, char *outtext, unsigned maxoutlen, cmdalias_t *alias ); void Cbuf_Execute (void) { -#define EXECUTESTRING_BUFFER 2048 int i; char *text; - char line[1024]; - char preprocessed[EXECUTESTRING_BUFFER]; + char line[MAX_INPUTLINE]; + char preprocessed[MAX_INPUTLINE]; int quotes; // LordHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes @@ -178,7 +182,7 @@ void Cbuf_Execute (void) } // execute the command line - Cmd_PreprocessString( line, preprocessed, EXECUTESTRING_BUFFER, NULL ); + Cmd_PreprocessString( line, preprocessed, sizeof(preprocessed), NULL ); Cmd_ExecuteString (preprocessed, src_command); if (cmd_wait) @@ -213,7 +217,7 @@ void Cmd_StuffCmds_f (void) { int i, j, l; // this is per command, and bounds checked (no buffer overflows) - char build[2048]; + char build[MAX_INPUTLINE]; if (Cmd_Argc () != 1) { @@ -308,7 +312,7 @@ Creates a new command that executes a command string (possibly ; seperated) static void Cmd_Alias_f (void) { cmdalias_t *a; - char cmd[1024]; + char cmd[MAX_INPUTLINE]; int i, c; const char *s; @@ -385,9 +389,6 @@ typedef struct cmd_function_s xcommand_t function; } cmd_function_t; - -#define MAX_ARGS 80 - static int cmd_argc; static const char *cmd_argv[MAX_ARGS]; static const char *cmd_null_string = ""; @@ -492,9 +493,8 @@ Called for aliases and fills in the alias into the cbuffer */ static void Cmd_ExecuteAlias (cmdalias_t *alias) { -#define ALIAS_BUFFER 1024 - static char buffer[ ALIAS_BUFFER + 2 ]; - Cmd_PreprocessString( alias->value, buffer, ALIAS_BUFFER, alias ); + static char buffer[ MAX_INPUTLINE + 2 ]; + Cmd_PreprocessString( alias->value, buffer, sizeof(buffer) - 2, alias ); Cbuf_AddText( buffer ); } diff --git a/common.c b/common.c index 00794c98..e7c5accd 100644 --- a/common.c +++ b/common.c @@ -32,13 +32,11 @@ cvar_t cmdline = {0, "cmdline","0"}; extern qboolean fs_modified; // set true if using non-id files -char com_token[1024]; +char com_token[MAX_INPUTLINE]; int com_argc; const char **com_argv; -// LordHavoc: made commandline 1024 characters instead of 256 -#define CMDLINE_LENGTH 1024 -char com_cmdline[CMDLINE_LENGTH]; +char com_cmdline[MAX_INPUTLINE]; gamemode_t gamemode; const char *gamename; @@ -420,7 +418,7 @@ float MSG_ReadBigFloat (void) char *MSG_ReadString (void) { - static char string[2048]; + static char string[MAX_INPUTLINE]; int l,c; for (l = 0;l < (int) sizeof(string) - 1 && (c = MSG_ReadChar()) != -1 && c != 0;l++) string[l] = c; @@ -879,16 +877,16 @@ void COM_InitArgv (void) { // arg contains whitespace, store quotes around it com_cmdline[n++] = '\"'; - while ((n < (CMDLINE_LENGTH - 1)) && com_argv[j][i]) + while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i]) com_cmdline[n++] = com_argv[j][i++]; com_cmdline[n++] = '\"'; } else { - while ((n < (CMDLINE_LENGTH - 1)) && com_argv[j][i]) + while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i]) com_cmdline[n++] = com_argv[j][i++]; } - if (n < (CMDLINE_LENGTH - 1)) + if (n < ((int)sizeof(com_cmdline) - 1)) com_cmdline[n++] = ' '; else break; @@ -1197,8 +1195,8 @@ int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *t // written by Elric, thanks Elric! char *SearchInfostring(const char *infostring, const char *key) { - static char value [256]; - char crt_key [256]; + static char value [MAX_INPUTLINE]; + char crt_key [MAX_INPUTLINE]; size_t value_ind, key_ind; char c; diff --git a/common.h b/common.h index 3f6c0dde..ffbcc8c1 100644 --- a/common.h +++ b/common.h @@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef COMMON_H #define COMMON_H +// many buffers use this size +#define MAX_INPUTLINE 16384 + // MSVC has a different name for several standard functions #ifdef WIN32 @@ -189,7 +192,7 @@ float MSG_ReadAngle (protocolversion_t protocol); //============================================================================ -extern char com_token[1024]; +extern char com_token[MAX_INPUTLINE]; int COM_ParseToken(const char **datapointer, int returnnewline); int COM_ParseTokenConsole(const char **datapointer); diff --git a/console.c b/console.c index 5eb85031..4b66cd75 100644 --- a/console.c +++ b/console.c @@ -368,7 +368,7 @@ void Con_Init (void) con_totallines = CON_TEXTSIZE / con_linewidth; // Allocate a log queue - logq_size = 512; + logq_size = MAX_INPUTLINE; logqueue = (unsigned char *)Mem_Alloc (tempmempool, logq_size); logq_ind = 0; @@ -535,7 +535,7 @@ void Con_Print(const char *msg) { int mask = 0; static int index = 0; - static char line[16384]; + static char line[MAX_INPUTLINE]; for (;*msg;msg++) { @@ -577,7 +577,7 @@ void Con_Print(const char *msg) // append the character line[index++] = *msg; // if this is a newline character, we have a complete line to print - if (*msg == '\n' || index >= 16000) + if (*msg == '\n' || index >= (int)sizeof(line) / 2) { // terminate the line line[index] = 0; @@ -601,9 +601,6 @@ void Con_Print(const char *msg) } -// LordHavoc: increased from 4096 to 16384 -#define MAXPRINTMSG 16384 - /* ================ Con_Printf @@ -614,7 +611,7 @@ Prints to all appropriate console targets void Con_Printf(const char *fmt, ...) { va_list argptr; - char msg[MAXPRINTMSG]; + char msg[MAX_INPUTLINE]; va_start(argptr,fmt); dpvsnprintf(msg,sizeof(msg),fmt,argptr); @@ -647,7 +644,7 @@ A Con_Printf that only shows up if the "developer" cvar is set void Con_DPrintf(const char *fmt, ...) { va_list argptr; - char msg[MAXPRINTMSG]; + char msg[MAX_INPUTLINE]; if (!developer.integer) return; // don't confuse non-developers with techie stuff... @@ -681,7 +678,7 @@ void Con_DrawInput (void) { int y; int i; - char editlinecopy[257], *text; + char editlinecopy[MAX_INPUTLINE+1], *text; if (!key_consoleactive) return; // don't draw anything @@ -696,7 +693,7 @@ void Con_DrawInput (void) y = (int)strlen(text); // fill out remainder with spaces - for (i = y; i < 256; i++) + for (i = y; i < (int)sizeof(editlinecopy)-1; i++) text[i] = ' '; // add the cursor frame @@ -730,8 +727,7 @@ void Con_DrawNotify (void) char *text; int i; float time; - extern char chat_buffer[256]; - char temptext[256]; + char temptext[MAX_INPUTLINE]; int colorindex = -1; //-1 for default if (con_notify.integer < 0) diff --git a/cvar.c b/cvar.c index 394a8327..655d91d2 100644 --- a/cvar.c +++ b/cvar.c @@ -252,7 +252,7 @@ Cvar_SetValue */ void Cvar_SetValueQuick(cvar_t *var, float value) { - char val[256]; + char val[MAX_INPUTLINE]; if ((float)((int)value) == value) sprintf(val, "%i", (int)value); @@ -263,7 +263,7 @@ void Cvar_SetValueQuick(cvar_t *var, float value) void Cvar_SetValue(const char *var_name, float value) { - char val[256]; + char val[MAX_INPUTLINE]; if ((float)((int)value) == value) sprintf(val, "%i", (int)value); diff --git a/fs.c b/fs.c index 46172798..fd20cdc1 100644 --- a/fs.c +++ b/fs.c @@ -1712,18 +1712,17 @@ Print a string into a file int FS_VPrintf (qfile_t* file, const char* format, va_list ap) { int len; - fs_offset_t buff_size; - char *tempbuff = NULL; + fs_offset_t buff_size = MAX_INPUTLINE; + char *tempbuff; - buff_size = 1024; - tempbuff = (char *)Mem_Alloc (tempmempool, buff_size); - len = dpvsnprintf (tempbuff, buff_size, format, ap); - while (len < 0) + for (;;) { - Mem_Free (tempbuff); - buff_size *= 2; tempbuff = (char *)Mem_Alloc (tempmempool, buff_size); len = dpvsnprintf (tempbuff, buff_size, format, ap); + if (len >= 0 && len < buff_size) + break; + Mem_Free (tempbuff); + buff_size *= 2; } len = write (file->handle, tempbuff, len); @@ -2219,7 +2218,7 @@ int FS_ListDirectory(const char *pattern, int oneperline) int linebufpos; int i, j, k, l; const char *name; - char linebuf[4096]; + char linebuf[MAX_INPUTLINE]; fssearch_t *search; search = FS_Search(pattern, true, true); if (!search) diff --git a/gl_backend.c b/gl_backend.c index 320e7e73..bb4d3dc0 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -757,7 +757,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver { GLint vertexshadercompiled, fragmentshadercompiled, programlinked; GLuint vertexshaderobject, fragmentshaderobject, programobject = 0; - char compilelog[4096]; + char compilelog[MAX_INPUTLINE]; CHECKGLERROR programobject = qglCreateProgramObjectARB(); diff --git a/host.c b/host.c index eaa32155..69d7547f 100644 --- a/host.c +++ b/host.c @@ -115,8 +115,8 @@ This shuts down both the client and server */ void Host_Error (const char *error, ...) { - static char hosterrorstring1[4096]; - static char hosterrorstring2[4096]; + static char hosterrorstring1[MAX_INPUTLINE]; + static char hosterrorstring2[MAX_INPUTLINE]; static qboolean hosterror = false; va_list argptr; @@ -306,7 +306,7 @@ FIXME: make this just a stuffed echo? void SV_ClientPrintf(const char *fmt, ...) { va_list argptr; - char msg[4096]; + char msg[MAX_INPUTLINE]; va_start(argptr,fmt); dpvsnprintf(msg,sizeof(msg),fmt,argptr); @@ -350,7 +350,7 @@ Sends text to all active clients void SV_BroadcastPrintf(const char *fmt, ...) { va_list argptr; - char msg[4096]; + char msg[MAX_INPUTLINE]; va_start(argptr,fmt); dpvsnprintf(msg,sizeof(msg),fmt,argptr); @@ -369,7 +369,7 @@ Send text over to the client to be executed void Host_ClientCommands(const char *fmt, ...) { va_list argptr; - char string[1024]; + char string[MAX_INPUTLINE]; va_start(argptr,fmt); dpvsnprintf(string, sizeof(string), fmt, argptr); diff --git a/host_cmd.c b/host_cmd.c index b3fd8db6..2ad0a7bc 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -460,7 +460,7 @@ Host_Savegame_f */ void Host_Savegame_f (void) { - char name[256]; + char name[MAX_QPATH]; qfile_t *f; int i; char comment[SAVEGAME_COMMENT_LENGTH+1]; @@ -903,8 +903,8 @@ void Host_Say(qboolean teamonly) int j, quoted; const char *p1; char *p2; - // LordHavoc: 256 char say messages - char text[256]; + // LordHavoc: long say messages + char text[1024]; qboolean fromServer = false; if (cmd_source == src_command) @@ -978,7 +978,7 @@ void Host_Tell_f(void) client_t *save; int j; const char *p1, *p2; - char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64) + char text[MAX_INPUTLINE]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64) qboolean fromServer = false; if (cmd_source == src_command) diff --git a/keys.c b/keys.c index 48d2da99..b9083439 100644 --- a/keys.c +++ b/keys.c @@ -603,7 +603,7 @@ static void Key_In_Bind_f (void) { int i, c, b, m; - char cmd[1024]; + char cmd[MAX_INPUTLINE]; c = Cmd_Argc (); @@ -705,7 +705,7 @@ static void Key_Bind_f (void) { int i, c, b; - char cmd[1024]; + char cmd[MAX_INPUTLINE]; c = Cmd_Argc (); diff --git a/keys.h b/keys.h index 70915a98..343b3112 100644 --- a/keys.h +++ b/keys.h @@ -188,7 +188,6 @@ keynum_t; typedef enum keydest_e { key_game, key_message, key_menu } keydest_t; #define MAX_INPUTLINES 32 -#define MAX_INPUTLINE 256 #define MAX_BINDMAPS 8 #define MAX_KEYS 1024 extern int edit_line; @@ -207,7 +206,7 @@ extern char *keybindings[MAX_BINDMAPS][MAX_KEYS]; extern void Key_ClearEditLine(int edit_line); extern qboolean chat_team; -extern char chat_buffer[256]; +extern char chat_buffer[MAX_INPUTLINE]; extern unsigned int chat_bufferlen; void Key_WriteBindings(qfile_t *f); diff --git a/menu.c b/menu.c index 17e65fd2..b9930581 100644 --- a/menu.c +++ b/menu.c @@ -2548,7 +2548,7 @@ void M_Keys_Draw (void) int keys[NUMKEYS]; int y; cachepic_t *p; - char keystring[1024]; + char keystring[MAX_INPUTLINE]; M_Background(320, 48 + 8 * numcommands); @@ -4618,7 +4618,7 @@ void MR_SetRouting (qboolean forceold); void MP_Error(const char *format, ...) { static qboolean processingError = false; - char errorstring[4096]; + char errorstring[MAX_INPUTLINE]; va_list argptr; va_start (argptr, format); diff --git a/model_brush.c b/model_brush.c index 26e731a5..b581ee24 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1158,7 +1158,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l) texture_t *tx, *tx2, *anims[10], *altanims[10]; dmiptexlump_t *m; unsigned char *data, *mtdata; - char name[256]; + char name[MAX_QPATH]; loadmodel->data_textures = NULL; @@ -1620,18 +1620,18 @@ static void Mod_Q1BSP_ParseWadsFromEntityLump(const char *data) key[strlen(key)-1] = 0; if (!COM_ParseToken(&data, false)) return; // error - strcpy(value, com_token); + dpsnprintf(value, sizeof(value), "%s", com_token); if (!strcmp("wad", key)) // for HalfLife maps { if (loadmodel->brush.ishlbsp) { j = 0; - for (i = 0;i < 4096;i++) + for (i = 0;i < (int)sizeof(value);i++) if (value[i] != ';' && value[i] != '\\' && value[i] != '/' && value[i] != ':') break; if (value[i]) { - for (;i < 4096;i++) + for (;i < (int)sizeof(value);i++) { // ignore path - the \\ check is for HalfLife... stupid windoze 'programmers'... if (value[i] == '\\' || value[i] == '/' || value[i] == ':') @@ -3782,7 +3782,7 @@ static int Mod_Q3BSP_NativeContentsFromSuperContents(model_t *model, int superco static void Mod_Q3BSP_LoadEntities(lump_t *l) { const char *data; - char key[128], value[4096]; + char key[128], value[MAX_INPUTLINE]; float v[3]; loadmodel->brushq3.num_lightgrid_cellsize[0] = 64; loadmodel->brushq3.num_lightgrid_cellsize[1] = 64; diff --git a/pr_cmds.c b/pr_cmds.c index 7d994956..0e84047b 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -25,7 +25,7 @@ cvar_t pr_zone_min_strings = {0, "pr_zone_min_strings", "64"}; // LordHavoc: added this to semi-fix the problem of using many ftos calls in a print #define STRINGTEMP_BUFFERS 16 -#define STRINGTEMP_LENGTH 4096 +#define STRINGTEMP_LENGTH MAX_INPUTLINE static char pr_string_temp[STRINGTEMP_BUFFERS][STRINGTEMP_LENGTH]; static int pr_string_tempindex = 0; @@ -3027,7 +3027,7 @@ void PF_clientcommand (void) //this function originally written by KrimZon, made shorter by LordHavoc //20040203: rewritten by LordHavoc (no longer uses allocations) int num_tokens = 0; -char *tokens[256], tokenbuf[4096]; +char *tokens[256], tokenbuf[MAX_INPUTLINE]; void PF_tokenize (void) { int pos; diff --git a/pr_edict.c b/pr_edict.c index d921f760..c05c684e 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -417,7 +417,7 @@ Returns a string describing *data in a type specific manner //int NoCrash_NUM_FOR_EDICT(prvm_edict_t *e); char *PR_ValueString (etype_t type, prvm_eval_t *val) { - static char line[1024]; // LordHavoc: enlarged a bit (was 256) + static char line[MAX_INPUTLINE]; ddef_t *def; mfunction_t *f; int n; @@ -477,7 +477,7 @@ Easier to parse than PR_ValueString */ char *PR_UglyValueString (etype_t type, prvm_eval_t *val) { - static char line[4096]; + static char line[MAX_INPUTLINE]; int i; const char *s; ddef_t *def; @@ -610,7 +610,7 @@ void ED_Print(prvm_edict_t *ed) int i, j; const char *name; int type; - char tempstring[8192], tempstring2[260]; // temporary string buffers + char tempstring[MAX_INPUTLINE], tempstring2[260]; // temporary string buffers if (ed->priv.server->free) { @@ -638,11 +638,11 @@ void ED_Print(prvm_edict_t *ed) if (j == type_size[type]) continue; - if (strlen(name) > 256) + if (strlen(name) > sizeof(tempstring2)-4) { - memcpy (tempstring2, name, 256); - tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; - tempstring2[259] = 0; + memcpy (tempstring2, name, sizeof(tempstring2)-4); + tempstring2[sizeof(tempstring2)-4] = tempstring2[sizeof(tempstring2)-3] = tempstring2[sizeof(tempstring2)-2] = '.'; + tempstring2[sizeof(tempstring2)-1] = 0; name = tempstring2; } strlcat (tempstring, name, sizeof (tempstring)); @@ -651,16 +651,16 @@ void ED_Print(prvm_edict_t *ed) strcat(tempstring, " "); name = PR_ValueString(d->type, (prvm_eval_t *)v); - if (strlen(name) > 256) + if (strlen(name) > sizeof(tempstring2)-4) { - memcpy(tempstring2, name, 256); - tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; - tempstring2[259] = 0; + memcpy (tempstring2, name, sizeof(tempstring2)-4); + tempstring2[sizeof(tempstring2)-4] = tempstring2[sizeof(tempstring2)-3] = tempstring2[sizeof(tempstring2)-2] = '.'; + tempstring2[sizeof(tempstring2)-1] = 0; name = tempstring2; } strlcat (tempstring, name, sizeof (tempstring)); strlcat (tempstring, "\n", sizeof (tempstring)); - if (strlen(tempstring) >= 4096) + if (strlen(tempstring) >= sizeof(tempstring)/2) { Con_Print(tempstring); tempstring[0] = 0; @@ -869,7 +869,7 @@ ED_ParseGlobals */ void ED_ParseGlobals (const char *data) { - char keyname[1024]; // LordHavoc: good idea? bad idea? was 64 + char keyname[MAX_INPUTLINE]; ddef_t *key; while (1) @@ -1499,7 +1499,7 @@ void PR_Fields_f (void) int i, j, ednum, used, usedamount; int *counts; const char *name; - char tempstring[5000], tempstring2[260]; + char tempstring[MAX_INPUTLINE], tempstring2[260]; prvm_edict_t *ed; ddef_t *d; int *v; @@ -1572,11 +1572,11 @@ void PR_Fields_f (void) strlcat (tempstring, tempstring2, sizeof (tempstring)); break; } - if (strlen(name) > 256) + if (strlen(name) > sizeof(tempstring2)-4) { - memcpy(tempstring2, name, 256); - tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; - tempstring2[259] = 0; + memcpy (tempstring2, name, sizeof(tempstring2)-4); + tempstring2[sizeof(tempstring2)-4] = tempstring2[sizeof(tempstring2)-3] = tempstring2[sizeof(tempstring2)-2] = '.'; + tempstring2[sizeof(tempstring2)-1] = 0; name = tempstring2; } strcat (tempstring, name); @@ -1585,7 +1585,7 @@ void PR_Fields_f (void) dpsnprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]); strlcat (tempstring, tempstring2, sizeof (tempstring)); strlcat (tempstring, "\n", sizeof (tempstring)); - if (strlen(tempstring) >= 4096) + if (strlen(tempstring) >= sizeof(tempstring)/2) { Con_Print(tempstring); tempstring[0] = 0; diff --git a/prvm_cmds.c b/prvm_cmds.c index cf7caeef..e82fa7f7 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1854,7 +1854,7 @@ float tokenize(string s) //this function originally written by KrimZon, made shorter by LordHavoc //20040203: rewritten by LordHavoc (no longer uses allocations) int num_tokens = 0; -char *tokens[256], tokenbuf[4096]; +char *tokens[256], tokenbuf[MAX_INPUTLINE]; void VM_tokenize (void) { size_t pos; diff --git a/prvm_cmds.h b/prvm_cmds.h index b77b39d6..51ccd3e3 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -201,7 +201,7 @@ float getserverlistindexforkey(string key) #define e1000 e100,e100,e100,e100,e100,e100,e100,e100,e100,e100 #define VM_STRINGTEMP_BUFFERS 16 -#define VM_STRINGTEMP_LENGTH 4096 +#define VM_STRINGTEMP_LENGTH MAX_INPUTLINE // builtins and other general functions diff --git a/prvm_edict.c b/prvm_edict.c index b4ab6735..f51ffcfc 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -368,7 +368,7 @@ Returns a string describing *data in a type specific manner */ char *PRVM_ValueString (etype_t type, prvm_eval_t *val) { - static char line[1024]; // LordHavoc: enlarged a bit (was 256) + static char line[MAX_INPUTLINE]; ddef_t *def; mfunction_t *f; int n; @@ -427,7 +427,7 @@ Easier to parse than PR_ValueString */ char *PRVM_UglyValueString (etype_t type, prvm_eval_t *val) { - static char line[4096]; + static char line[MAX_INPUTLINE]; int i; const char *s; ddef_t *def; @@ -560,7 +560,7 @@ void PRVM_ED_Print(prvm_edict_t *ed) int i, j; const char *name; int type; - char tempstring[8192], tempstring2[260]; // temporary string buffers + char tempstring[MAX_INPUTLINE], tempstring2[260]; // temporary string buffers if (ed->priv.required->free) { @@ -588,11 +588,11 @@ void PRVM_ED_Print(prvm_edict_t *ed) if (j == prvm_type_size[type]) continue; - if (strlen(name) > 256) + if (strlen(name) > sizeof(tempstring2)-4) { - memcpy (tempstring2, name, 256); - tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; - tempstring2[259] = 0; + memcpy (tempstring2, name, sizeof(tempstring2)-4); + tempstring2[sizeof(tempstring2)-4] = tempstring2[sizeof(tempstring2)-3] = tempstring2[sizeof(tempstring2)-2] = '.'; + tempstring2[sizeof(tempstring2)-1] = 0; name = tempstring2; } strcat(tempstring, name); @@ -601,16 +601,16 @@ void PRVM_ED_Print(prvm_edict_t *ed) strcat(tempstring, " "); name = PRVM_ValueString((etype_t)d->type, (prvm_eval_t *)v); - if (strlen(name) > 256) + if (strlen(name) > sizeof(tempstring2)-4) { - memcpy (tempstring2, name, 256); - tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; - tempstring2[259] = 0; + memcpy (tempstring2, name, sizeof(tempstring2)-4); + tempstring2[sizeof(tempstring2)-4] = tempstring2[sizeof(tempstring2)-3] = tempstring2[sizeof(tempstring2)-2] = '.'; + tempstring2[sizeof(tempstring2)-1] = 0; name = tempstring2; } strcat(tempstring, name); strcat(tempstring, "\n"); - if (strlen(tempstring) >= 4096) + if (strlen(tempstring) >= sizeof(tempstring)/2) { Con_Print(tempstring); tempstring[0] = 0; @@ -825,7 +825,7 @@ PRVM_ED_ParseGlobals */ void PRVM_ED_ParseGlobals (const char *data) { - char keyname[1024]; // LordHavoc: good idea? bad idea? was 64 + char keyname[MAX_INPUTLINE]; ddef_t *key; while (1) @@ -1535,7 +1535,7 @@ void PRVM_Fields_f (void) { int i, j, ednum, used, usedamount; int *counts; - char tempstring[5000], tempstring2[260]; + char tempstring[MAX_INPUTLINE], tempstring2[260]; const char *name; prvm_edict_t *ed; ddef_t *d; @@ -1624,11 +1624,11 @@ void PRVM_Fields_f (void) strcat(tempstring, tempstring2); break; } - if (strlen(name) > 256) + if (strlen(name) > sizeof(tempstring2)-4) { - memcpy (tempstring2, name, 256); - tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; - tempstring2[259] = 0; + memcpy (tempstring2, name, sizeof(tempstring2)-4); + tempstring2[sizeof(tempstring2)-4] = tempstring2[sizeof(tempstring2)-3] = tempstring2[sizeof(tempstring2)-2] = '.'; + tempstring2[sizeof(tempstring2)-1] = 0; name = tempstring2; } strcat(tempstring, name); @@ -1637,7 +1637,7 @@ void PRVM_Fields_f (void) sprintf(tempstring2, "%5d", counts[i]); strcat(tempstring, tempstring2); strcat(tempstring, "\n"); - if (strlen(tempstring) >= 4096) + if (strlen(tempstring) >= sizeof(tempstring)/2) { Con_Print(tempstring); tempstring[0] = 0; diff --git a/r_shadow.c b/r_shadow.c index 1b5a8600..c1f71e14 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -3288,7 +3288,7 @@ void R_Shadow_SaveWorldLights(void) size_t bufchars, bufmaxchars; char *buf, *oldbuf; char name[MAX_QPATH]; - char line[1024]; + char line[MAX_INPUTLINE]; if (!r_shadow_worldlightchain) return; if (r_refdef.worldmodel == NULL) @@ -3390,7 +3390,7 @@ void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void) char *entfiledata; const char *data; float origin[3], angles[3], radius, color[3], light[4], fadescale, lightscale, originhack[3], overridecolor[3], vec[4]; - char key[256], value[1024]; + char key[256], value[MAX_INPUTLINE]; if (r_refdef.worldmodel == NULL) { @@ -3701,7 +3701,7 @@ void R_Shadow_EditLights_Edit_f(void) vec3_t origin, angles, color; vec_t radius, corona, coronasizescale, ambientscale, diffusescale, specularscale; int style, shadows, flags, normalmode, realtimemode; - char cubemapname[1024]; + char cubemapname[MAX_INPUTLINE]; if (!r_editlights.integer) { Con_Print("Cannot spawn light when not in editing mode. Set r_editlights to 1.\n"); @@ -3718,7 +3718,7 @@ void R_Shadow_EditLights_Edit_f(void) radius = r_shadow_selectedlight->radius; style = r_shadow_selectedlight->style; if (r_shadow_selectedlight->cubemapname) - strcpy(cubemapname, r_shadow_selectedlight->cubemapname); + strlcpy(cubemapname, r_shadow_selectedlight->cubemapname, sizeof(cubemapname)); else cubemapname[0] = 0; shadows = r_shadow_selectedlight->shadow; diff --git a/r_sky.c b/r_sky.c index 9f5e311f..981ba57c 100644 --- a/r_sky.c +++ b/r_sky.c @@ -12,7 +12,7 @@ int skyrendermasked; static int skyrendersphere; static int skyrenderbox; static rtexturepool_t *skytexturepool; -static char skyname[256]; +static char skyname[MAX_QPATH]; typedef struct suffixinfo_s { @@ -88,7 +88,7 @@ int R_LoadSkyBox(void) { int i, j, success; int indices[4] = {0,1,2,3}; - char name[1024]; + char name[MAX_INPUTLINE]; unsigned char *image_rgba; unsigned char *temp; diff --git a/sys_linux.c b/sys_linux.c index 1d77ae23..9b6aa09e 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -32,7 +32,7 @@ void Sys_Shutdown (void) void Sys_Error (const char *error, ...) { va_list argptr; - char string[1024]; + char string[MAX_INPUTLINE]; // change stdin to non blocking #ifndef WIN32 @@ -141,7 +141,7 @@ char *Sys_ConsoleInput(void) { if (cls.state == ca_dedicated) { - static char text[256]; + static char text[MAX_INPUTLINE]; static unsigned int len = 0; #ifdef WIN32 int c; diff --git a/sys_sdl.c b/sys_sdl.c index 39c57df9..4187d529 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -30,7 +30,7 @@ void Sys_Shutdown (void) void Sys_Error (const char *error, ...) { va_list argptr; - char string[1024]; + char string[MAX_INPUTLINE]; // change stdin to non blocking #ifndef WIN32 @@ -83,7 +83,7 @@ char *Sys_ConsoleInput(void) { if (cls.state == ca_dedicated) { - static char text[256]; + static char text[MAX_INPUTLINE]; int len = 0; #ifdef WIN32 int c; diff --git a/sys_win.c b/sys_win.c index e48c2616..b9b4cd38 100644 --- a/sys_win.c +++ b/sys_win.c @@ -50,7 +50,7 @@ SYSTEM IO void Sys_Error (const char *error, ...) { va_list argptr; - char text[1024]; + char text[MAX_INPUTLINE]; static int in_sys_error0 = 0; static int in_sys_error1 = 0; static int in_sys_error2 = 0; @@ -196,7 +196,7 @@ double Sys_DoubleTime (void) char *Sys_ConsoleInput (void) { - static char text[256]; + static char text[MAX_INPUTLINE]; static int len; INPUT_RECORD recs[1024]; int ch;