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
This commit is contained in:
helixhorned 2012-03-18 23:18:32 +00:00
parent 9628041766
commit 97020caf73
3 changed files with 34 additions and 56 deletions

View file

@ -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;
}

View file

@ -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++;
}

View file

@ -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++;
}