From 97020caf735aba155aec8a022bd7d54cbb797bc0 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 18 Mar 2012 23:18:32 +0000 Subject: [PATCH] Clear up after r2495. (Because I'm a pedantic asshole.) - in Mapster, pre-form the default 10 clip map names before returning from G_CheckCommandLine() so it gets loaded even if we passed no cmdline args. - malloc + strlen + strcpy --> strdup - don't need to spank dead variables ;) - we may call calloc with zero size, which isn't bad by itself, but asserting for non-null afterwards is. Allocs of 0 are implementation-defined, and may well return a null pointer (C99 7.20.3). git-svn-id: https://svn.eduke32.com/eduke32@2502 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/engine.c | 62 +++++++++++------------------- polymer/eduke32/source/astub.c | 22 +++++------ polymer/eduke32/source/game.c | 6 +-- 3 files changed, 34 insertions(+), 56 deletions(-) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 8574ba81e..8d6042353 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -1285,10 +1285,10 @@ int32_t clipmapinfo_load(void) return 1; } - fisec = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t)); - assert(fisec); - fispr = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t)); - assert(fispr); + if (g_clipMapFilesNum) + fisec = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t)); + if (g_clipMapFilesNum) + fispr = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t)); quickloadboard = 1; for (fi = 0; fi < g_clipMapFilesNum; ++fi) @@ -1341,10 +1341,8 @@ int32_t clipmapinfo_load(void) { clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return -1; } @@ -1366,10 +1364,8 @@ int32_t clipmapinfo_load(void) { clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 1; } @@ -1411,10 +1407,8 @@ int32_t clipmapinfo_load(void) { clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 1; } @@ -1449,10 +1443,8 @@ int32_t clipmapinfo_load(void) clipinfo[sectoidx[k]].picnum); clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 2; } @@ -1515,10 +1507,8 @@ int32_t clipmapinfo_load(void) " for sprite %d.\n", g_clipMapFiles[fi], outersect-fisec[fi], ns-fisec[fi], i-fispr[fi]); clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 3; } @@ -1536,10 +1526,8 @@ int32_t clipmapinfo_load(void) g_clipMapFiles[fi], ns-fisec[fi], sectoidx[ns], i-fispr[fi], numclipmaps); clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 4; } @@ -1553,10 +1541,8 @@ int32_t clipmapinfo_load(void) initprintf("clip map: INTERNAL ERROR: outersect==-1!\n"); clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 5; } @@ -1660,10 +1646,8 @@ int32_t clipmapinfo_load(void) { clipmapinfo_init(); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 1; } @@ -1732,10 +1716,8 @@ int32_t clipmapinfo_load(void) if (lwcp > 0) initprintf("Loaded clip map%s.\n", lwcp==1?"":"s"); - free(fisec); - fisec = NULL; - free(fispr); - fispr = NULL; + Bfree(fisec); + Bfree(fispr); return 0; } diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 69ba55d09..444aade1c 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -8448,6 +8448,15 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) mapster32_fullpath = argv[0]; + // pre-form the default 10 clipmaps + for (j = '0'; j<='9'; ++j) + { + clipshape[10] = j; + g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); + g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(clipshape); + ++g_clipMapFilesNum; + } + if (argc <= 1) return; @@ -8461,16 +8470,6 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) testplay_addparam = Bmalloc(maxlen+argc); testplay_addparam[0] = 0; - // pre-form the default 10 clipmaps - for (j = '0'; j<='9'; ++j) - { - clipshape[10] = j; - g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); - g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen(clipshape) + 1); - Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], clipshape); - ++g_clipMapFilesNum; - } - j = 0; while (i < argc) @@ -8610,8 +8609,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) if (argc > i+1) { g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); - g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen((char *)argv[i+1]) + 1); - Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], (char *)argv[i+1]); + g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(argv[i+1]); ++g_clipMapFilesNum; i++; } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index c7f362bd5..d4b6df307 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8614,8 +8614,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { clipshape[10] = j; g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); - g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen(clipshape) + 1); - Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], clipshape); + g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(clipshape); ++g_clipMapFilesNum; } @@ -8853,8 +8852,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) if (argc > i+1) { g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); - g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen((char *)argv[i+1]) + 1); - Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], (char *)argv[i+1]); + g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(argv[i+1]); ++g_clipMapFilesNum; i++; }