From 4f584291375b146b50398b22ead976f74b33b1ff Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 20 Aug 2018 00:05:00 +0900 Subject: [PATCH] Fix an unhealthy pile of gcc 8 warnings. While some of the warnings were merely annoying, some where actual bugs or unearthed bugs in related code. --- include/QF/model.h | 4 +- include/QF/teamplay.h | 2 +- libs/models/alias/gl_model_alias.c | 35 ++++++------ libs/models/brush/gl_model_brush.c | 4 +- libs/models/brush/model_brush.c | 26 +++++---- libs/models/gl_model_fullbright.c | 2 +- libs/util/pakfile.c | 2 +- libs/util/wadfile.c | 2 +- libs/video/renderer/gl/gl_draw.c | 3 +- nq/source/cl_demo.c | 23 ++++---- nq/source/sbar.c | 2 +- qw/include/server.h | 2 +- qw/source/cl_cmd.c | 38 ++++++++----- qw/source/cl_demo.c | 22 ++++---- qw/source/sbar.c | 2 +- qw/source/sv_init.c | 6 +- qw/source/sv_main.c | 8 +-- qw/source/sv_send.c | 89 ++++++++++++++++-------------- qw/source/teamplay.c | 39 ++++++------- tools/qfspritegen/spritegen.c | 18 +++--- 20 files changed, 178 insertions(+), 151 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index b4d7791cd..641e025ec 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -90,7 +90,7 @@ typedef struct instsurf_s { } instsurf_t; typedef struct texture_s { - char name[16]; + char *name; unsigned int width, height; int gl_texturenum; int gl_fb_texturenum; @@ -445,7 +445,7 @@ mleaf_t *Mod_PointInLeaf (const vec3_t p, model_t *model); byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model); model_t *Mod_FindName (const char *name); int Mod_CalcFullbright (byte *in, byte *out, int pixels); -int Mod_Fullbright (byte * skin, int width, int height, char *name); +int Mod_Fullbright (byte * skin, int width, int height, const char *name); void *Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame, int extra); diff --git a/include/QF/teamplay.h b/include/QF/teamplay.h index b0b1c01da..bf4ae9445 100644 --- a/include/QF/teamplay.h +++ b/include/QF/teamplay.h @@ -43,7 +43,7 @@ void Team_Init_Cvars (void); void Team_BestWeaponImpulse (void); void Team_Dead (void); void Team_NewMap (void); -const char *Team_ParseSay (const char *); +const char *Team_ParseSay (struct dstring_s *buf, const char *); void Locs_Init (void); void Team_ParseChat (const char *string); void Team_ResetTimers (void); diff --git a/libs/models/alias/gl_model_alias.c b/libs/models/alias/gl_model_alias.c index ec304b80d..63618451e 100644 --- a/libs/models/alias/gl_model_alias.c +++ b/libs/models/alias/gl_model_alias.c @@ -38,6 +38,7 @@ # include #endif +#include "QF/dstring.h" #include "QF/image.h" #include "QF/qendian.h" #include "QF/quakefs.h" @@ -56,8 +57,9 @@ gl_Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, maliasskindesc_t *skindesc) { byte *pskin; - char name[32], modname[MAX_QPATH + 4]; + char modname[MAX_QPATH + 4]; int fb_texnum = 0, texnum = 0; + dstring_t *name = dstring_new (); pskin = Hunk_AllocName (skinsize, loadname); skindesc->skin = (byte *) pskin - (byte *) pheader; @@ -75,27 +77,26 @@ gl_Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, if (!loadmodel->fullbright) { if (group) { - snprintf (name, sizeof (name), "fb_%s_%i_%i", modname, - snum, gnum); + dsprintf (name, "fb_%s_%i_%i", modname, snum, gnum); } else { - snprintf (name, sizeof (name), "fb_%s_%i", modname, snum); + dsprintf (name, "fb_%s_%i", modname, snum); } fb_texnum = Mod_Fullbright (pskin, pheader->mdl.skinwidth, - pheader->mdl.skinheight, name); - Sys_MaskPrintf (SYS_GLT, "%s %d\n", name, fb_texnum); + pheader->mdl.skinheight, name->str); + Sys_MaskPrintf (SYS_GLT, "%s %d\n", name->str, fb_texnum); } if (group) { - snprintf (name, sizeof (name), "%s_%i_%i", modname, snum, - gnum); + dsprintf (name, "%s_%i_%i", modname, snum, gnum); } else { - snprintf (name, sizeof (name), "%s_%i", modname, snum); + dsprintf (name, "%s_%i", modname, snum); } - texnum = GL_LoadTexture (name, pheader->mdl.skinwidth, + texnum = GL_LoadTexture (name->str, pheader->mdl.skinwidth, pheader->mdl.skinheight, pskin, true, false, 1); - Sys_MaskPrintf (SYS_GLT, "%s %d\n", name, texnum); + Sys_MaskPrintf (SYS_GLT, "%s %d\n", name->str, texnum); skindesc->texnum = texnum; skindesc->fb_texnum = fb_texnum; loadmodel->hasfullbrights = fb_texnum; + dstring_delete (name); // alpha param was true for non group skins return skin + skinsize; } @@ -151,10 +152,11 @@ Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename) void gl_Mod_LoadExternalSkins (model_t *mod) { - char filename[MAX_QPATH + 4], modname[MAX_QPATH + 4]; + char modname[MAX_QPATH + 4]; int i, j; maliasskindesc_t *pskindesc; maliasskingroup_t *pskingroup; + dstring_t *filename = dstring_new (); QFS_StripExtension (mod->name, modname); @@ -162,16 +164,15 @@ gl_Mod_LoadExternalSkins (model_t *mod) pskindesc = ((maliasskindesc_t *) ((byte *) pheader + pheader->skindesc)) + i; if (pskindesc->type == ALIAS_SKIN_SINGLE) { - snprintf (filename, sizeof (filename), "%s_%i", modname, i); - Mod_LoadExternalSkin (pskindesc, filename); + dsprintf (filename, "%s_%i", modname, i); + Mod_LoadExternalSkin (pskindesc, filename->str); } else { pskingroup = (maliasskingroup_t *) ((byte *) pheader + pskindesc->skin); for (j = 0; j < pskingroup->numskins; j++) { - snprintf (filename, sizeof (filename), "%s_%i_%i", - modname, i, j); - Mod_LoadExternalSkin (pskingroup->skindescs + j, filename); + dsprintf (filename, "%s_%i_%i", modname, i, j); + Mod_LoadExternalSkin (pskingroup->skindescs + j, filename->str); } } } diff --git a/libs/models/brush/gl_model_brush.c b/libs/models/brush/gl_model_brush.c index 18744a529..1485fdd94 100644 --- a/libs/models/brush/gl_model_brush.c +++ b/libs/models/brush/gl_model_brush.c @@ -55,11 +55,11 @@ void gl_Mod_ProcessTexture (texture_t *tx) { - char name[32]; + const char *name; if (!strncmp (tx->name, "sky", 3)) return; - snprintf (name, sizeof (name), "fb_%s", tx->name); + name = va ("fb_%s", tx->name); tx->gl_fb_texturenum = Mod_Fullbright ((byte *) (tx + 1), tx->width, tx->height, name); tx->gl_texturenum = diff --git a/libs/models/brush/model_brush.c b/libs/models/brush/model_brush.c index 931575534..dd43c1dc8 100644 --- a/libs/models/brush/model_brush.c +++ b/libs/models/brush/model_brush.c @@ -42,6 +42,7 @@ #include "QF/checksum.h" #include "QF/cvar.h" +#include "QF/dstring.h" #include "QF/model.h" #include "QF/qendian.h" #include "QF/quakefs.h" @@ -132,25 +133,28 @@ Mod_LeafPVS (mleaf_t *leaf, model_t *model) static void mod_unique_miptex_name (texture_t **textures, texture_t *tx, int ind) { - char name[17]; + char *name; int num = 0, i; - const char *tag; + dstring_t *tag = 0; - strncpy (name, tx->name, 16); - name[16] = 0; + name = tx->name; do { for (i = 0; i < ind; i++) if (textures[i] && !strcmp (textures[i]->name, tx->name)) break; if (i == ind) break; - tag = va ("~%x", num++); - strncpy (tx->name, name, 16); - if (strlen (name) + strlen (tag) <= 15) - strcat (tx->name, tag); - else - strcpy (tx->name + 15 - strlen (tag), tag); + if (!tag) { + tag = dstring_new (); + } + dsprintf (tag, "%s~%x", name, num++); + tx->name = tag->str; } while (1); + + if (tag) { + tx->name = dstring_freeze (tag); + free(name); + } } static void @@ -188,7 +192,7 @@ Mod_LoadTextures (bsp_t *bsp) loadmodel->textures[i] = tx; - memcpy (tx->name, mt->name, sizeof (tx->name)); + tx->name = strndup(mt->name, sizeof (mt->name)); mod_unique_miptex_name (loadmodel->textures, tx, i); tx->width = mt->width; tx->height = mt->height; diff --git a/libs/models/gl_model_fullbright.c b/libs/models/gl_model_fullbright.c index f556c5dd7..3417b6646 100644 --- a/libs/models/gl_model_fullbright.c +++ b/libs/models/gl_model_fullbright.c @@ -59,7 +59,7 @@ Mod_CalcFullbright (byte *in, byte *out, int pixels) } int -Mod_Fullbright (byte *skin, int width, int height, char *name) +Mod_Fullbright (byte *skin, int width, int height, const char *name) { byte *ptexels; int pixels; diff --git a/libs/util/pakfile.c b/libs/util/pakfile.c index 5ddbbb9a2..9cfcb9924 100644 --- a/libs/util/pakfile.c +++ b/libs/util/pakfile.c @@ -161,7 +161,7 @@ pack_create (const char *name) pack_del (pack); return 0; } - strncpy (pack->header.id, "PACK", sizeof (pack->header.id)); + memcpy (pack->header.id, "PACK", sizeof (pack->header.id)); Qwrite (pack->handle, &pack->header, sizeof (pack->header)); diff --git a/libs/util/wadfile.c b/libs/util/wadfile.c index d5bf7c7fd..3175f22c7 100644 --- a/libs/util/wadfile.c +++ b/libs/util/wadfile.c @@ -182,7 +182,7 @@ wad_create (const char *name) wad_del (wad); return 0; } - strncpy (wad->header.id, "WAD2", sizeof (wad->header.id)); + memcpy (wad->header.id, "WAD2", sizeof (wad->header.id)); Qwrite (wad->handle, &wad->header, sizeof (wad->header)); diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index f988ddf66..6cebda1fb 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -256,7 +256,8 @@ gl_Draw_CachePic (const char *path, qboolean alpha) } else Sys_Error ("Draw_CachePic: failed to load %s", path); - strncpy (pic->name, path, sizeof (pic->name)); + memset (pic->name, 0, sizeof (pic->name)); + strncpy (pic->name, path, sizeof (pic->name) - 1); // Now lets mark this cache entry as used.. pic->dirty = false; diff --git a/nq/source/cl_demo.c b/nq/source/cl_demo.c index 026c59fbb..3b0a1a803 100644 --- a/nq/source/cl_demo.c +++ b/nq/source/cl_demo.c @@ -56,15 +56,15 @@ typedef struct { double fps; } td_stats_t; -int demo_timeframes_isactive; -int demo_timeframes_index; -char demoname[1024]; -double *demo_timeframes_array; +static int demo_timeframes_isactive; +static int demo_timeframes_index; +static dstring_t *demoname; +static double *demo_timeframes_array; #define CL_TIMEFRAMES_ARRAYBLOCK 4096 -int timedemo_count; -int timedemo_runs; -td_stats_t *timedemo_data; +static int timedemo_count; +static int timedemo_runs; +static td_stats_t *timedemo_data; static void CL_FinishTimeDemo (void); static void CL_TimeFrames_DumpLog (void); @@ -450,7 +450,7 @@ CL_StartDemo (void) CL_Disconnect (); // open the demo file - name = dstring_strdup (demoname); + name = dstring_strdup (demoname->str); QFS_DefaultExtension (name, ".dem"); Sys_Printf ("Playing demo from %s.\n", name->str); @@ -499,7 +499,7 @@ CL_PlayDemo_f (void) switch (Cmd_Argc ()) { case 1: - if (!demoname[0]) + if (!demoname->str[0]) goto playdemo_error; // fall through case 2: @@ -519,7 +519,7 @@ playdemo_error: timedemo_runs = timedemo_count = 1; // make sure looped timedemos stop if (Cmd_Argc () > 1) - strncpy (demoname, Cmd_Argv (1), sizeof (demoname)); + dstring_copystr (demoname, Cmd_Argv (1)); CL_StartDemo (); } @@ -627,7 +627,7 @@ CL_TimeDemo_f (void) timedemo_data = 0; } timedemo_data = calloc (timedemo_runs, sizeof (td_stats_t)); - strncpy (demoname, Cmd_Argv (1), sizeof (demoname)); + dstring_copystr (demoname, Cmd_Argv (1)); CL_StartTimeDemo (); timedemo_runs = timedemo_count = max (count, 1); timedemo_data = calloc (timedemo_runs, sizeof (td_stats_t)); @@ -636,6 +636,7 @@ CL_TimeDemo_f (void) void CL_Demo_Init (void) { + demoname = dstring_newstr (); demo_timeframes_isactive = 0; demo_timeframes_index = 0; demo_timeframes_array = NULL; diff --git a/nq/source/sbar.c b/nq/source/sbar.c index e77ff103a..44d911118 100644 --- a/nq/source/sbar.c +++ b/nq/source/sbar.c @@ -352,7 +352,7 @@ draw_num (view_t *view, int x, int y, int num, int digits, int color) static inline void draw_smallnum (view_t *view, int x, int y, int n, int packed, int colored) { - char num[4]; + char num[12]; packed = packed != 0; // ensure 0 or 1 diff --git a/qw/include/server.h b/qw/include/server.h index dbda77e12..642f296f8 100644 --- a/qw/include/server.h +++ b/qw/include/server.h @@ -73,7 +73,7 @@ typedef struct { unsigned int model_player_checksum; unsigned int eyes_player_checksum; - char name[64]; // map name + char *name; // map name char modelname[MAX_QPATH]; // maps/.bsp, for model_precache[0] struct model_s *worldmodel; const char *model_precache[MAX_MODELS]; // NULL terminated diff --git a/qw/source/cl_cmd.c b/qw/source/cl_cmd.c index 1b02d4581..a38dbc875 100644 --- a/qw/source/cl_cmd.c +++ b/qw/source/cl_cmd.c @@ -37,12 +37,33 @@ #include "QF/cbuf.h" #include "QF/cmd.h" +#include "QF/dstring.h" #include "QF/msg.h" #include "QF/sys.h" #include "QF/teamplay.h" #include "client.h" +static void +send_say (const char *str) +{ + static dstring_t *teambuf; + const char *s; + + if (!teambuf) { + teambuf = dstring_newstr (); + } + + s = Team_ParseSay (teambuf, Cmd_Args (1)); + if (*s && *s < 32 && *s != 10) { + // otherwise the server would eat leading characters + // less than 32 or greater than 127 + SZ_Print (&cls.netchan.message, "\""); + SZ_Print (&cls.netchan.message, s); + SZ_Print (&cls.netchan.message, "\""); + } else + SZ_Print (&cls.netchan.message, s); +} /* CL_Cmd_ForwardToServer @@ -70,21 +91,10 @@ CL_Cmd_ForwardToServer (void) if (!strcasecmp (Cmd_Argv (0), "say") || !strcasecmp (Cmd_Argv (0), "say_team")) { - const char *s; - - s = Team_ParseSay (Cmd_Args (1)); - if (*s && *s < 32 && *s != 10) { - // otherwise the server would eat leading characters - // less than 32 or greater than 127 - SZ_Print (&cls.netchan.message, "\""); - SZ_Print (&cls.netchan.message, s); - SZ_Print (&cls.netchan.message, "\""); - } else - SZ_Print (&cls.netchan.message, s); - return; + send_say(Cmd_Args (1)); + } else { + SZ_Print (&cls.netchan.message, Cmd_Args (1)); } - - SZ_Print (&cls.netchan.message, Cmd_Args (1)); } } diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 31ce11620..04ccbdf55 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -69,14 +69,14 @@ typedef struct { double fps; } td_stats_t; -int demo_timeframes_isactive; -int demo_timeframes_index; +static int demo_timeframes_isactive; +static int demo_timeframes_index; static int demotime_cached; static float cached_demotime; static byte cached_newtime; -float nextdemotime; -char demoname[1024]; -double *demo_timeframes_array; +static float nextdemotime; +static dstring_t *demoname; +static double *demo_timeframes_array; #define CL_TIMEFRAMES_ARRAYBLOCK 4096 int timedemo_count; @@ -990,12 +990,12 @@ CL_StartDemo (void) int type; // open the demo file - name = dstring_strdup (demoname); + name = dstring_strdup (demoname->str); QFS_DefaultExtension (name, ".mvd"); cls.demofile = QFS_FOpenFile (name->str); if (!cls.demofile) { - dstring_copystr (name, demoname); + dstring_copystr (name, demoname->str); QFS_DefaultExtension (name, ".qwd"); cls.demofile = QFS_FOpenFile (name->str); } @@ -1050,7 +1050,7 @@ CL_PlayDemo_f (void) { switch (Cmd_Argc ()) { case 1: - if (!demoname[0]) + if (!demoname->str[0]) goto playdemo_error; // fall through case 2: @@ -1072,7 +1072,7 @@ playdemo_error: CL_Disconnect (); if (Cmd_Argc () > 1) - strncpy (demoname, Cmd_Argv (1), sizeof (demoname)); + dstring_copystr (demoname, Cmd_Argv (1)); CL_StartDemo (); } @@ -1182,7 +1182,7 @@ CL_TimeDemo_f (void) timedemo_data = 0; } timedemo_data = calloc (timedemo_runs, sizeof (td_stats_t)); - strncpy (demoname, Cmd_Argv (1), sizeof (demoname)); + dstring_copystr (demoname, Cmd_Argv (1)); CL_StartTimeDemo (); timedemo_runs = timedemo_count = max (count, 1); timedemo_data = calloc (timedemo_runs, sizeof (td_stats_t)); @@ -1191,6 +1191,8 @@ CL_TimeDemo_f (void) void CL_Demo_Init (void) { + demoname = dstring_newstr (); + demo_timeframes_isactive = 0; demo_timeframes_index = 0; demo_timeframes_array = NULL; diff --git a/qw/source/sbar.c b/qw/source/sbar.c index 7234c7f51..34490e43e 100644 --- a/qw/source/sbar.c +++ b/qw/source/sbar.c @@ -476,7 +476,7 @@ draw_solo (view_t *view) static inline void draw_smallnum (view_t *view, int x, int y, int n, int packed, int colored) { - char num[4]; + char num[12]; packed = packed != 0; // ensure 0 or 1 diff --git a/qw/source/sv_init.c b/qw/source/sv_init.c index b9dbb0aec..7d8c894d1 100644 --- a/qw/source/sv_init.c +++ b/qw/source/sv_init.c @@ -341,6 +341,9 @@ SV_SpawnServer (const char *server) so_buffers = sv.signon_buffers; so_sizes = sv.signon_buffer_size; + if (sv.name) { + free (sv.name); + } memset (&sv, 0, sizeof (sv)); sv.recorders = recorders; @@ -363,7 +366,7 @@ SV_SpawnServer (const char *server) SV_NextSignon (); - strcpy (sv.name, server); + sv.name = strdup(server); // load progs to get entity field count which determines how big each // edict is @@ -384,7 +387,6 @@ SV_SpawnServer (const char *server) sv.time = 1.0; - strncpy (sv.name, server, sizeof (sv.name)); snprintf (sv.modelname, sizeof (sv.modelname), "maps/%s.bsp", server); map_cfg (sv.modelname, 0); sv.worldmodel = Mod_ForName (sv.modelname, true); diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index 42a313aa6..685dfd0a7 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -1430,7 +1430,7 @@ SV_AddIP_f (void) // FIXME: this should boot any matching clients for (i = 0; i < MAX_CLIENTS; i++) { client_t *cl = &svs.clients[i]; - char text[1024]; + const char *text; const char *typestr; char timestr[1024]; @@ -1461,9 +1461,9 @@ SV_AddIP_f (void) bantime / 60); else strncpy (timestr, "permanently", sizeof (timestr)); - snprintf (text, sizeof (text), "You are %s %s\n%s", - typestr, timestr, type == ft_ban ? "" : - "\nReconnecting won't help..."); + text = va ("You are %s %s\n%s", + typestr, timestr, type == ft_ban ? "" : + "\nReconnecting won't help..."); MSG_ReliableWrite_Begin (&cl->backbuf, svc_centerprint, strlen (text) + 2); MSG_ReliableWrite_String (&cl->backbuf, text); diff --git a/qw/source/sv_send.c b/qw/source/sv_send.c index 58fb00bef..54e53d347 100644 --- a/qw/source/sv_send.c +++ b/qw/source/sv_send.c @@ -148,6 +148,20 @@ SV_EndRedirect (void) } #define MAXPRINTMSG 4096 +static int +find_userid (const char *name) +{ + int i; + + for (i = 0; i < MAX_CLIENTS; i++) { + if (!svs.clients[i].state) + continue; + if (!strcmp (svs.clients[i].name, name)) { + return svs.clients[i].userid; + } + } + return 0; +} /* SV_Printf @@ -158,10 +172,11 @@ SV_EndRedirect (void) void SV_Print (const char *fmt, va_list args) { + static dstring_t *premsg; + static dstring_t *msg; + static dstring_t *msg2; static int pending = 0; // partial line being printed - char premsg[MAXPRINTMSG]; - unsigned char msg[MAXPRINTMSG]; - char msg2[MAXPRINTMSG]; + char msg3[MAXPRINTMSG]; time_t mytime = 0; @@ -169,50 +184,42 @@ SV_Print (const char *fmt, va_list args) qboolean timestamps = false; char *in; - unsigned char *out; - vsnprintf (premsg, sizeof (premsg), fmt, args); - in = premsg; - out = msg; + if (!premsg) { + premsg = dstring_newstr (); + msg = dstring_new (); + msg2 = dstring_new (); + } + dstring_clearstr (msg); - if (!*premsg) + dvsprintf (premsg, fmt, args); + in = premsg->str; + + if (!*premsg->str) return; // expand FFnickFF to nick do { - switch ((byte) *in) { - case 0xFF: { - char *end = strchr (in + 1, 0xFF); - int userid = 0; - int len; - int i; - - if (!end) - end = in + strlen (in); - *end = '\0'; - for (i = 0; i < MAX_CLIENTS; i++) { - if (!svs.clients[i].state) - continue; - if (!strcmp (svs.clients[i].name, in + 1)) { - userid = svs.clients[i].userid; - break; - } - } - len = snprintf ((char *) out, sizeof (msg) - (out - msg), - "%s <%d>", in + 1, userid); - out += len; - in = end + 1; - break; + char *beg = strchr (in, 0xFF); + if (beg) { + char *name = beg + 1; + char *end = strchr (name, 0xFF); + if (!end) { + end = beg + strlen (name); } - default: - *out++ = *in++; + *end = 0; + dstring_appendsubstr (msg, in, beg - in); + dasprintf (msg, "%s <%d>", name, find_userid (name)); + in = end + 1; + } else { + dstring_appendstr (msg, in); + break; } - } while (sizeof (msg) - (out - msg) > 0 && *in); - *out = '\0'; + } while (*in); if (sv_redirected) { // Add to redirected message - dstring_appendstr (&outputbuf, (char *) msg); + dstring_appendstr (&outputbuf, msg->str); } - if (*msg && !con_printf_no_log) { + if (*msg->str && !con_printf_no_log) { // We want to output to console and maybe logfile if (sv_timestamps && sv_timefmt && sv_timefmt->string && sv_timestamps->int_val && !pending) @@ -223,17 +230,17 @@ SV_Print (const char *fmt, va_list args) local = localtime (&mytime); strftime (msg3, sizeof (msg3), sv_timefmt->string, local); - snprintf (msg2, sizeof (msg2), "%s%s", msg3, msg); + dsprintf (msg2, "%s%s", msg3, msg->str); } else { - snprintf (msg2, sizeof (msg2), "%s", msg); + dsprintf (msg2, "%s", msg->str); } - if (msg2[strlen (msg2) - 1] != '\n') { + if (msg2->str[strlen (msg2->str) - 1] != '\n') { pending = 1; } else { pending = 0; } - Con_Printf ("%s", msg2); // also echo to debugging console + Con_Printf ("%s", msg2->str); // also echo to debugging console } } diff --git a/qw/source/teamplay.c b/qw/source/teamplay.c index 513fdd4f7..538dc0f1d 100644 --- a/qw/source/teamplay.c +++ b/qw/source/teamplay.c @@ -117,13 +117,12 @@ Team_BestWeaponImpulse (void) in_impulse = best; } - -const char * -Team_ParseSay (const char *s) +//FIXME slow use of dstring +const char * +Team_ParseSay (dstring_t *buf, const char *s) { - char chr, t2[128], t3[128]; + char chr, t2[128], t3[2]; const char *t1; - static char buf[1024]; size_t i, bracket; static location_t *location = NULL; @@ -213,8 +212,9 @@ Team_ParseSay (const char *s) snprintf (t2, sizeof (t2), "%sa:%i", t3, cl.stats[STAT_ARMOR]); - } else + } else { snprintf (t2, sizeof (t2), "%i", cl.stats[STAT_ARMOR]); + } break; case 'A': bracket = 0; @@ -254,29 +254,24 @@ Team_ParseSay (const char *s) t1 = t2; } - if (bracket) - buf[i++] = 0x90; // '[' - - if (t1) { - int len; - - len = strlen (t1); - if (i + len >= sizeof (buf)) - continue; // No more space in buffer, icky. - strncpy (buf + i, t1, len); - i += len; + if (bracket) { + dstring_appendstr (buf, "\x90"); // '[' } - if (bracket) - buf[i++] = 0x91; // ']' + if (t1) { + dstring_appendstr (buf, t1); + } + + if (bracket) { + dstring_appendstr (buf, "\x91"); // ']' + } continue; } - buf[i++] = *s++; + dstring_appendsubstr (buf, s++, 1); } - buf[i] = 0; - return buf; + return buf->str; } void diff --git a/tools/qfspritegen/spritegen.c b/tools/qfspritegen/spritegen.c index b209650d4..5234adc0c 100644 --- a/tools/qfspritegen/spritegen.c +++ b/tools/qfspritegen/spritegen.c @@ -27,6 +27,7 @@ #include #include +#include "QF/dstring.h" #include "QF/image.h" #include "QF/pcx.h" #include "QF/qendian.h" @@ -42,8 +43,8 @@ tex_t *image; dsprite_t sprite; byte *lumpbuffer, *plump; -char spritedir[1024]; -char spriteoutname[1024]; +dstring_t *spritedir; +dstring_t *spriteoutname; int framesmaxs[2]; int framecount; @@ -444,7 +445,7 @@ Cmd_Spritename (void) FinishSprite (); Script_GetToken (&scr, false); - sprintf (spriteoutname, "%s%s.spr", spritedir, Script_Token (&scr)); + dsprintf (spriteoutname, "%s%s.spr", spritedir->str, Script_Token (&scr)); memset (&sprite, 0, sizeof(sprite)); framecount = 0; @@ -472,14 +473,14 @@ FinishSprite (void) if (sprite.numframes == 0) Sys_Error ("no frames\n"); - if (!strlen(spriteoutname)) + if (!spriteoutname->str) Sys_Error ("Didn't name sprite file"); if ((plump - lumpbuffer) > MAX_BUFFER_SIZE) Sys_Error ("Sprite package too big; increase MAX_BUFFER_SIZE"); - spriteouthandle = Qopen (spriteoutname, "wb"); - printf ("saving in %s\n", spriteoutname); + spriteouthandle = Qopen (spriteoutname->str, "wb"); + printf ("saving in %s\n", spriteoutname->str); WriteSprite (spriteouthandle); Qclose (spriteouthandle); @@ -487,7 +488,7 @@ FinishSprite (void) printf ("%d frame(s)\n", sprite.numframes); printf ("%d ungrouped frame(s), including group headers\n", framecount); - spriteoutname[0] = 0; // clear for a new sprite + dstring_clearstr (spriteoutname); // clear for a new sprite } /* @@ -505,6 +506,9 @@ int main (int argc, char **argv) if (argc != 2) Sys_Error ("usage: spritegen file.qc"); + spritedir = dstring_newstr (); + spriteoutname = dstring_newstr (); + i = 1; //SetQdirFromPath (argv[i]);