From c4efd9b1fa74619aaf63ec8e855b8a639b3e9463 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 25 Mar 2012 22:00:42 +0000 Subject: [PATCH] Take over more correct G_AddGroup from game.c to astub.c. The code in the editor was potentially doing a strcat on a strdup'd string. Also, rename AddGamePath to G_AddPath in astub.c and add CODEDUP markers because shared stuff like this ought to be factored out into a separate source file some time. git-svn-id: https://svn.eduke32.com/eduke32@2531 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/astub.c | 28 ++++++++++++++++++---------- polymer/eduke32/source/game.c | 9 +++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index cedb06086..5075d636c 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -8380,10 +8380,11 @@ static void G_ShowParameterHelp(void) wm_msgbox(tempbuf, "%s", s); } -static void AddGamePath(const char *buffer) + +// CODEDUP game.c +static void G_AddPath(const char *buffer) { - struct strllist *s; - s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); + struct strllist *s = Bcalloc(1,sizeof(struct strllist)); s->str = Bstrdup(buffer); if (CommandPaths) @@ -8393,16 +8394,23 @@ static void AddGamePath(const char *buffer) t->next = s; return; } + CommandPaths = s; } +// CODEDUP game.c static void G_AddGroup(const char *buffer) { - struct strllist *s; - s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); - s->str = Bstrdup(buffer); - if (Bstrchr(s->str,'.') == 0) - Bstrcat(s->str,".grp"); + char buf[BMAX_PATH]; + + struct strllist *s = Bcalloc(1,sizeof(struct strllist)); + + Bstrcpy(buf, buffer); + + if (Bstrchr(buf,'.') == 0) + Bstrcat(buf,".grp"); + + s->str = Bstrdup(buf); if (CommandGrps) { @@ -8498,7 +8506,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) #endif Bstrncpy(g_modDir, argv[i+1], sizeof(g_modDir)); g_modDir[sizeof(g_modDir)-1] = 0; - AddGamePath(argv[i+1]); + G_AddPath(argv[i+1]); COPYARG(i); COPYARG(i+1); @@ -8685,7 +8693,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) case 'J': c++; if (!*c) break; - AddGamePath(c); + G_AddPath(c); COPYARG(i); break; case 'g': diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index b53a7cfdb..cb37cfe80 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8567,12 +8567,13 @@ static int32_t loaddefinitions_game(const char *fn, int32_t preload) return 0; } + +// CODEDUP astub.c static void G_AddGroup(const char *buffer) { - struct strllist *s; char buf[BMAX_PATH]; - s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); + struct strllist *s = Bcalloc(1,sizeof(struct strllist)); Bstrcpy(buf, buffer); @@ -8591,10 +8592,10 @@ static void G_AddGroup(const char *buffer) CommandGrps = s; } +// CODEDUP astub.c static void G_AddPath(const char *buffer) { - struct strllist *s; - s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); + struct strllist *s = Bcalloc(1,sizeof(struct strllist)); s->str = Bstrdup(buffer); if (CommandPaths)