Bye, bye, B*alloc(), all hail X*alloc()! Replace large portion of the calls...

... and cull code that is dead with the X*alloc() versions since they never
return NULL on requesting memory.

Use something like
 git grep '[^Xx]\(m\|c\|re\)alloc *('
and
 git grep '[^Xx]strdup *('
to see places where I left the B*alloc() calls intact.

BUILD_LUNATIC.

git-svn-id: https://svn.eduke32.com/eduke32@4491 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-05-30 00:02:19 +00:00
parent 1d26121514
commit 0900f4066c
40 changed files with 432 additions and 899 deletions

View file

@ -139,7 +139,7 @@ typedef struct pthtyp_t
struct pthtyp_t *ofb; // only fullbright
} pthtyp;
extern int32_t gloadtile_art(int32_t,int32_t,int32_t,int32_t,pthtyp *,int32_t);
extern void gloadtile_art(int32_t,int32_t,int32_t,int32_t,pthtyp *,int32_t);
extern int32_t gloadtile_hi(int32_t,int32_t,int32_t,hicreplctyp *,int32_t,pthtyp *,int32_t,char);
extern int32_t globalnoeffect;

View file

@ -10,7 +10,7 @@
enum texcacherr_t
{
TEXCACHERR_NOERROR,
TEXCACHERR_OUTOFMEMORY,
TEXCACHERR_OUTOFMEMORY, /* unused */
TEXCACHERR_BUFFERUNDERRUN,
TEXCACHERR_DEDXT,
TEXCACHERR_COMPTEX,

View file

@ -1466,21 +1466,9 @@ void drawsmallabel(const char *text, char col, char backcol, int32_t dax, int32_
}
}
static void free_n_ptrs(void **ptrptr, int32_t n)
{
int32_t i;
for (i=0; i<n; i++)
{
Bfree(ptrptr[i]);
ptrptr[i] = NULL;
}
}
// backup highlighted sectors with sprites as mapinfo for later restoration
// return values:
// -1: highlightsectorcnt<=0
// -2: out of mem
// 0: ok
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
{
@ -1491,8 +1479,6 @@ static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
int16_t otonbunch[YAX_MAXBUNCHES];
int16_t numsectsofbunch[YAX_MAXBUNCHES]; // ceilings + floors
#endif
int32_t np = 0;
void *ptrs[5];
if (highlightsectorcnt <= 0)
return -1;
@ -1560,20 +1546,14 @@ static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
}
// allocate temp storage
ptrs[np++] = mapinfo->sector = (sectortype *)Bmalloc(highlightsectorcnt * sizeof(sectortype));
if (!mapinfo->sector) return -2;
ptrs[np++] = mapinfo->wall = (walltype *)Bmalloc(tmpnumwalls * sizeof(walltype));
if (!mapinfo->wall) { free_n_ptrs(ptrs, np-1); return -2; }
mapinfo->sector = (sectortype *)Xmalloc(highlightsectorcnt * sizeof(sectortype));
mapinfo->wall = (walltype *)Xmalloc(tmpnumwalls * sizeof(walltype));
#ifdef YAX_ENABLE
if (mapinfo->numyaxbunches > 0)
{
ptrs[np++] = mapinfo->bunchnum = (int16_t *)Bmalloc(highlightsectorcnt*2*sizeof(int16_t));
if (!mapinfo->bunchnum) { free_n_ptrs(ptrs, np-1); return -2; }
ptrs[np++] = mapinfo->ynextwall = (int16_t *)Bmalloc(tmpnumwalls*2*sizeof(int16_t));
if (!mapinfo->ynextwall) { free_n_ptrs(ptrs, np-1); return -2; }
mapinfo->bunchnum = (int16_t *)Xmalloc(highlightsectorcnt*2*sizeof(int16_t));
mapinfo->ynextwall = (int16_t *)Xmalloc(tmpnumwalls*2*sizeof(int16_t));
}
else
{
@ -1583,8 +1563,7 @@ static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
if (tmpnumsprites>0)
{
ptrs[np++] = mapinfo->sprite = (spritetype *)Bmalloc(tmpnumsprites * sizeof(spritetype));
if (!mapinfo->sprite) { free_n_ptrs(ptrs, np-1); return -2; }
mapinfo->sprite = (spritetype *)Xmalloc(tmpnumsprites * sizeof(spritetype));
}
else
{
@ -2445,9 +2424,7 @@ static int32_t backup_drawn_walls(int32_t restore)
return 2;
Bfree(tmpwall);
tmpwall = (walltype *)Bmalloc((newnumwalls-numwalls) * sizeof(walltype));
if (!tmpwall)
return 1;
tmpwall = (walltype *)Xmalloc((newnumwalls-numwalls) * sizeof(walltype));
ovh.bak_wallsdrawn = newnumwalls-numwalls;
@ -2764,14 +2741,12 @@ static int32_t bakframe_fillandfade(char **origframeptr, int32_t sectnum, const
{
if (!*origframeptr)
{
*origframeptr = (char *)Bmalloc(xdim*ydim);
if (*origframeptr)
{
*origframeptr = (char *)Xmalloc(xdim*ydim);
begindrawing();
Bmemcpy(*origframeptr, (char *)frameplace, xdim*ydim);
enddrawing();
}
}
else
{
begindrawing();
@ -5031,17 +5006,8 @@ end_yax: ;
sector[refsect].wallnum += n;
if (refsect != numsectors-1)
{
walltype *tmpwall = (walltype *)Bmalloc(n * sizeof(walltype));
int16_t *tmponw = (int16_t *)Bmalloc(n * sizeof(int16_t));
if (!tmpwall || !tmponw)
{
message("out of memory!");
ExtUnInit();
// clearfilenames();
uninitengine();
exit(1);
}
walltype *tmpwall = (walltype *)Xmalloc(n * sizeof(walltype));
int16_t *tmponw = (int16_t *)Xmalloc(n * sizeof(int16_t));
for (m=0; m<numwalls; m++)
{
@ -10696,7 +10662,7 @@ void test_map(int32_t mode)
// and a possible extra space not in testplay_addparam,
// the length should be Bstrlen(game_executable)+Bstrlen(param)+(slen+1)+2+1.
fullparam = (char *)Bmalloc(Bstrlen(game_executable)+Bstrlen(param)+slen+4);
fullparam = (char *)Xmalloc(Bstrlen(game_executable)+Bstrlen(param)+slen+4);
Bsprintf(fullparam,"\"%s\"",game_executable);
if (testplay_addparam)

View file

@ -157,9 +157,7 @@ void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr)
{
UNREFERENCED_PARAMETER(newlockptr);
*newhandle = (intptr_t)Bmalloc(newbytes);
if (!*newhandle)
reportandexit("OUT OF MEMORY in allocache as malloc wrapper!");
*newhandle = (intptr_t)Xmalloc(newbytes);
}
#else
static void inc_and_check_cacnum(void)
@ -357,7 +355,7 @@ int32_t addsearchpath(const char *p)
struct Bstat st;
char *s;
searchpath_t *srch;
char *path = Bstrdup(p);
char *path = Xstrdup(p);
if (path[Bstrlen(path)-1] == '\\')
path[Bstrlen(path)-1] = 0; // hack for stat() returning ENOENT on paths ending in a backslash
@ -374,22 +372,11 @@ int32_t addsearchpath(const char *p)
return -1;
}
srch = (searchpath_t *)Bmalloc(sizeof(searchpath_t));
if (!srch)
{
Bfree(path);
return -1;
}
srch = (searchpath_t *)Xmalloc(sizeof(searchpath_t));
srch->next = searchpathhead;
srch->pathlen = Bstrlen(path)+1;
srch->path = (char *)Bmalloc(srch->pathlen + 1);
if (!srch->path)
{
Bfree(path);
Bfree(srch);
return -1;
}
srch->path = (char *)Xmalloc(srch->pathlen + 1);
Bstrcpy(srch->path, path);
for (s=srch->path; *s; s++);
@ -414,7 +401,7 @@ int32_t removesearchpath(const char *p)
{
searchpath_t *srch;
char *s;
char *path = (char *)Bmalloc(Bstrlen(p) + 2);
char *path = (char *)Xmalloc(Bstrlen(p) + 2);
Bstrcpy(path, p);
@ -476,13 +463,13 @@ int32_t findfrompath(const char *fn, char **where)
// test unmolested filename first
if (access(fn, F_OK) >= 0)
{
*where = Bstrdup(fn);
*where = Xstrdup(fn);
return 0;
}
#ifndef _WIN32
else
{
char *tfn = Bstrtolower(Bstrdup(fn));
char *tfn = Bstrtolower(Xstrdup(fn));
if (access(tfn, F_OK) >= 0)
{
@ -504,16 +491,15 @@ int32_t findfrompath(const char *fn, char **where)
}
for (pfn = (char *)fn; toupperlookup[*pfn] == '/'; pfn++);
ffn = Bstrdup(pfn);
if (!ffn) return -1;
ffn = Xstrdup(pfn);
Bcorrectfilename(ffn,0); // compress relative paths
allocsiz = max(maxsearchpathlen, 2); // "./" (aka. curdir)
allocsiz += strlen(ffn);
allocsiz += 1; // a nul
pfn = (char *)Bmalloc(allocsiz);
if (!pfn) { Bfree(ffn); return -1; }
pfn = (char *)Xmalloc(allocsiz);
strcpy(pfn, "./");
strcat(pfn, ffn);
@ -526,7 +512,7 @@ int32_t findfrompath(const char *fn, char **where)
for (sp = searchpathhead; sp; sp = sp->next)
{
char *tfn = Bstrdup(ffn);
char *tfn = Xstrdup(ffn);
strcpy(pfn, sp->path);
strcat(pfn, ffn);
@ -702,16 +688,8 @@ int32_t initgroupfile(const char *filename)
}
gnumfiles[numgroupfiles] = B_LITTLE32(*((int32_t *)&buf[12]));
if ((gfilelist[numgroupfiles] = (char *)Bmalloc(gnumfiles[numgroupfiles]<<4)) == 0)
{
Bprintf("Not enough memory for file grouping system\n");
exit(1);
}
if ((gfileoffs[numgroupfiles] = (int32_t *)Bmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0)
{
Bprintf("Not enough memory for file grouping system\n");
exit(1);
}
gfilelist[numgroupfiles] = (char *)Xmalloc(gnumfiles[numgroupfiles]<<4);
gfileoffs[numgroupfiles] = (int32_t *)Xmalloc((gnumfiles[numgroupfiles]+1)<<2);
Bread(groupfil[numgroupfiles],gfilelist[numgroupfiles],gnumfiles[numgroupfiles]<<4);
@ -820,7 +798,7 @@ static int32_t check_filename_mismatch(const char *filename, int32_t ofs)
return 0;
{
char *tfn = Bstrtolower(Bstrdup(fn));
char *tfn = Bstrtolower(Xstrdup(fn));
if (!Bstrncmp(shinf.szDisplayName, tfn, len))
{
@ -1167,8 +1145,8 @@ static int32_t klistaddentry(CACHE1D_FIND_REC **rec, const char *name, int32_t t
return 0;
}
r = (CACHE1D_FIND_REC *)Bmalloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1);
if (!r) return -1;
r = (CACHE1D_FIND_REC *)Xmalloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1);
r->name = (char *)r + sizeof(CACHE1D_FIND_REC); strcpy(r->name, name);
r->type = type;
r->source = source;
@ -1212,8 +1190,7 @@ CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int32_t type)
// pathsearchmode == 0: enumerates a path in the virtual filesystem
// pathsearchmode == 1: enumerates the system filesystem path passed in
path = Bstrdup(_path);
if (!path) return NULL;
path = Xstrdup(_path);
// we don't need any leading dots and slashes or trailing slashes either
{

View file

@ -254,7 +254,7 @@ int32_t loadsetup(const char *fn)
if (readconfig(fp, val, val, VL) <= 0)
break;
scripthist[i] = Bstrdup(val);
scripthist[i] = Xstrdup(val);
}
scripthistend = i;
@ -278,7 +278,7 @@ int32_t loadsetup(const char *fn)
void writesettings(void) // save binds and aliases to <cfgname>_m32_settings.cfg
{
BFILE *fp;
char *ptr = Bstrdup(setupfilename);
char *ptr = Xstrdup(setupfilename);
char tempbuf[128];
if (!Bstrcmp(setupfilename, SETUPFILENAME))

View file

@ -174,9 +174,9 @@ static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t
const int32_t xsiz = tilesizx[tile], ysiz = tilesizy[tile];
int32_t i, j;
char *ftd = (char *)Bmalloc(xsiz*ysiz);
char *ftd = (char *)Xmalloc(xsiz*ysiz);
faketiledata[tile] = (char *)Bmalloc(xsiz*ysiz + 400);
faketiledata[tile] = (char *)Xmalloc(xsiz*ysiz + 400);
for (i=xsiz-1; i>=0; i--)
{
@ -1561,7 +1561,7 @@ static int32_t defsparser(scriptfile *script)
fd = kopen4load(fn, 0);
// load the highpalookup and send it to polymer
highpaldata = (char *)Bmalloc(PR_HIGHPALOOKUP_DATA_SIZE);
highpaldata = (char *)Xmalloc(PR_HIGHPALOOKUP_DATA_SIZE);
{
char *filebuf;
@ -1569,8 +1569,7 @@ static int32_t defsparser(scriptfile *script)
filesize = kfilelength(fd);
filebuf = (char *)Bmalloc(filesize);
if (!filebuf) { kclose(fd); Bfree(highpaldata); break; }
filebuf = (char *)Xmalloc(filesize);
klseek(fd, 0, SEEK_SET);
if (kread(fd, filebuf, filesize)!=filesize)

View file

@ -925,15 +925,8 @@ void yax_preparedrawrooms(void)
if (getrendermode() == REND_CLASSIC && ymostallocsize < xdimen*numyaxbunches)
{
ymostallocsize = xdimen*numyaxbunches;
yumost = (int16_t *)Brealloc(yumost, ymostallocsize*sizeof(int16_t));
ydmost = (int16_t *)Brealloc(ydmost, ymostallocsize*sizeof(int16_t));
if (!yumost || !ydmost)
{
initprintf("OUT OF MEMORY in yax_preparedrawrooms!\n");
uninitengine();
exit(10);
}
yumost = (int16_t *)Xrealloc(yumost, ymostallocsize*sizeof(int16_t));
ydmost = (int16_t *)Xrealloc(ydmost, ymostallocsize*sizeof(int16_t));
}
}
@ -1391,20 +1384,14 @@ int32_t clipmapinfo_load(void)
clipmapinfo_init();
loadsector = (sectortype *)Bmalloc(MAXSECTORS * sizeof(sectortype));
loadwall = (walltype *)Bmalloc(MAXWALLS * sizeof(walltype));
loadsprite = (spritetype *)Bmalloc(MAXSPRITES * sizeof(spritetype));
if (!loadsector || !loadwall || !loadsprite)
{
clipmapinfo_init();
return 1;
}
loadsector = (sectortype *)Xmalloc(MAXSECTORS * sizeof(sectortype));
loadwall = (walltype *)Xmalloc(MAXWALLS * sizeof(walltype));
loadsprite = (spritetype *)Xmalloc(MAXSPRITES * sizeof(spritetype));
if (g_clipMapFilesNum)
fisec = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t));
fisec = (int32_t *)Xcalloc(g_clipMapFilesNum, sizeof (int32_t));
if (g_clipMapFilesNum)
fispr = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t));
fispr = (int32_t *)Xcalloc(g_clipMapFilesNum, sizeof (int32_t));
quickloadboard = 1;
for (fi = 0; fi < g_clipMapFilesNum; ++fi)
@ -1467,8 +1454,8 @@ int32_t clipmapinfo_load(void)
}
// shrink
loadsector = (sectortype *)Brealloc(loadsector, ournumsectors*sizeof(sectortype));
loadwall = (walltype *)Brealloc(loadwall, ournumwalls*sizeof(walltype));
loadsector = (sectortype *)Xrealloc(loadsector, ournumsectors*sizeof(sectortype));
loadwall = (walltype *)Xrealloc(loadwall, ournumwalls*sizeof(walltype));
Bmemcpy(sector, loadsector, ournumsectors*sizeof(sectortype));
Bmemcpy(wall, loadwall, ournumwalls*sizeof(walltype));
@ -1478,16 +1465,8 @@ int32_t clipmapinfo_load(void)
// vvvv don't use headsprite[sect,stat]! vvvv
sectoidx = (int16_t *)Bmalloc(numsectors*sizeof(sectoidx[0]));
if (!sectoidx || !sector || !wall)
{
clipmapinfo_init();
sectoidx = (int16_t *)Xmalloc(numsectors*sizeof(sectoidx[0]));
Bfree(fisec);
Bfree(fispr);
return 1;
}
for (i=0; i<numsectors; i++)
sectoidx[i] = CM_NONE;
@ -1520,17 +1499,9 @@ int32_t clipmapinfo_load(void)
int16_t ns, outersect;
int32_t pn,scnt, x,y,z, maxdist;
sectq = (int16_t *)Bmalloc(numsectors*sizeof(sectq[0]));
tempictoidx = (int16_t *)Bmalloc(MAXTILES*sizeof(tempictoidx[0]));
if (!sectq || !tempictoidx)
{
clipmapinfo_init();
sectq = (int16_t *)Xmalloc(numsectors*sizeof(sectq[0]));
tempictoidx = (int16_t *)Xmalloc(MAXTILES*sizeof(tempictoidx[0]));
Bfree(fisec);
Bfree(fispr);
return 1;
}
for (i=0; i<MAXTILES; i++)
tempictoidx[i]=-1;
@ -1760,16 +1731,7 @@ int32_t clipmapinfo_load(void)
Bmemcpy(loadwall, wall, ournumwalls*sizeof(walltype));
// loadwallinv will contain all walls with inverted orientation for x/y-flip handling
loadwallinv = (walltype *)Bmalloc(ournumwalls*sizeof(walltype));
if (!loadwallinv)
{
clipmapinfo_init();
Bfree(fisec);
Bfree(fispr);
return 1;
}
loadwallinv = (walltype *)Xmalloc(ournumwalls*sizeof(walltype));
{
int32_t j, loopstart, loopend, numloopwalls;
@ -8020,12 +7982,12 @@ static void initfastcolorlookup(int32_t rscale, int32_t gscale, int32_t bscale)
static void alloc_palookup(int32_t pal)
{
#if defined ENGINE_USING_A_C || (defined CLASSIC_NONPOW2_YSIZE_WALLS && defined CLASSIC_NONPOW2_YSIZE_SPRITES)
palookup[pal] = (char *)Bmalloc(numshades*256);
palookup[pal] = (char *)Xmalloc(numshades*256);
#else
// The asm functions vlineasm1, mvlineasm1 (maybe others?) access the next
// palookup[...] shade entry for tilesizy==512 tiles.
// See DEBUG_TILESIZY_512 and the comment in a.nasm: vlineasm1.
palookup[pal] = (char *)Bcalloc(numshades+1, 256);
palookup[pal] = (char *)Xcalloc(numshades+1, 256);
#endif
}
@ -8056,9 +8018,7 @@ static int32_t loadpalette(void)
alloc_palookup(0);
transluc = (char *)Bcalloc(256, 256);
if (palookup[0] == NULL || transluc == NULL)
return loadpalette_err("Out of memory in loadpalette()!");
transluc = (char *)Xcalloc(256, 256);
globalpalwritten = palookup[0]; globalpal = 0;
setpalookupaddress(globalpalwritten);
@ -8114,10 +8074,7 @@ static int32_t loadpalette(void)
{
// Read in additional blending tables.
uint8_t addblendtabs, blendnum;
char *tab = (char *)Bmalloc(256*256);
if (tab == NULL)
return loadpalette_err("failed allocating temporary blending table");
char *tab = (char *)Xmalloc(256*256);
if (kread(fil, &addblendtabs, 1) != 1)
return loadpalette_err("failed reading additional blending table count");
@ -10050,24 +10007,12 @@ static void E_RecalcPicSiz(void)
template <typename origar_t, typename bakar_t>
static inline void ALLOC_MAPART_ARRAY(origar_t &origar, bakar_t &bakar)
{
bakar = (bakar_t) Bmalloc(MAXUSERTILES*sizeof(origar[0]));
if (bakar == NULL)
{
initprintf("OUT OF MEMORY allocating per-map ART backup arrays!\n");
uninitengine();
exit(12);
}
bakar = (bakar_t)Xmalloc(MAXUSERTILES*sizeof(origar[0]));
Bmemcpy(bakar, origar, MAXUSERTILES*sizeof(origar[0]));
}
#else
#define ALLOC_MAPART_ARRAY(origar, bakar) do { \
bakar = Bmalloc(MAXUSERTILES*sizeof(origar[0])); \
if (bakar == NULL) \
{ \
initprintf("OUT OF MEMORY allocating per-map ART backup arrays!\n"); \
uninitengine(); \
exit(12); \
} \
bakar = Xmalloc(MAXUSERTILES*sizeof(origar[0])); \
Bmemcpy(bakar, origar, MAXUSERTILES*sizeof(origar[0])); \
} while (0)
#endif
@ -11138,12 +11083,9 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
while (1) // if, really
{
sectortypev7 *const tsect = (sectortypev7 *)Bmalloc(sizeof(sectortypev7) * numsectors);
sectortypev7 *const tsect = (sectortypev7 *)Xmalloc(sizeof(sectortypev7) * numsectors);
walltypev7 *twall;
if (tsect == NULL)
break;
#ifdef NEW_MAP_FORMAT
for (i=0; i<numsectors; i++)
copy_v7_from_vx_sector(&tsect[i], &sector[i]);
@ -11187,10 +11129,7 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
ts = B_LITTLE16(numwalls);
Bwrite(fil,&ts,2);
twall = (walltypev7 *)Bmalloc(sizeof(walltypev7) * numwalls);
if (twall == NULL)
break;
twall = (walltypev7 *)Xmalloc(sizeof(walltypev7) * numwalls);
#ifdef NEW_MAP_FORMAT
for (i=0; i<numwalls; i++)
@ -11234,12 +11173,9 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
if (numsprites > 0)
{
spritetype *const tspri = (spritetype *)Bmalloc(sizeof(spritetype) * numsprites);
spritetype *const tspri = (spritetype *)Xmalloc(sizeof(spritetype) * numsprites);
spritetype *spri = tspri;
if (tspri == NULL)
break;
for (j=0; j<MAXSPRITES; j++)
{
if (sprite[j].statnum != MAXSTATUS)
@ -11326,14 +11262,7 @@ int32_t setgamemode(char davidoption, int32_t daxdim, int32_t daydim, int32_t da
Bfree(lookups);
j = ydim*4; //Leave room for horizlookup&horizlookup2
lookups = (int32_t *)Bmalloc(2*j*sizeof(lookups[0]));
if (lookups == NULL)
{
initprintf("OUT OF MEMORY in setgamemode!\n");
uninitengine();
exit(1);
}
lookups = (int32_t *)Xmalloc(2*j*sizeof(lookups[0]));
horizlookup = lookups;
horizlookup2 = lookups + j;
@ -11610,7 +11539,7 @@ static int32_t E_ReadArtFile(int32_t tilefilei)
if (cache1d_file_fromzip(fil)) // from zip
{
i = kfilelength(fil);
artptrs[tilefilei] = (char *)Brealloc(artptrs[tilefilei], i);
artptrs[tilefilei] = (char *)Xrealloc(artptrs[tilefilei], i);
klseek(fil, 0, BSEEK_SET);
kread(fil, artptrs[tilefilei], i);
}
@ -11652,6 +11581,7 @@ int32_t loadpics(const char *filename, int32_t askedsize)
else
cachesize = askedsize;
// NOTE: this doesn't make a lot of sense on modern OSs...
while ((pic = Bmalloc(cachesize)) == NULL)
{
cachesize -= 65536;
@ -14893,11 +14823,7 @@ static void maybe_alloc_palookup(int32_t palnum)
void setblendtab(int32_t blend, const char *tab)
{
if (blendtable[blend] == NULL)
{
blendtable[blend] = (char *)Bmalloc(256*256);
if (blendtable[blend] == NULL)
exit(1);
}
blendtable[blend] = (char *)Xmalloc(256*256);
Bmemcpy(blendtable[blend], tab, 256*256);
}
@ -15687,12 +15613,7 @@ void setfirstwall(int16_t sectnum, int16_t newfirstwall)
if (newfirstwall < startwall || newfirstwall >= startwall+danumwalls)
return;
tmpwall = (walltype *)Bmalloc(danumwalls * sizeof(walltype));
if (!tmpwall)
{
initprintf("setfirstwall: OUT OF MEMORY!\n");
return;
}
tmpwall = (walltype *)Xmalloc(danumwalls * sizeof(walltype));
Bmemcpy(tmpwall, &wall[startwall], danumwalls*sizeof(walltype));
@ -17407,7 +17328,7 @@ static int32_t screencapture_tga(const char *filename, char inverseit)
int32_t i;
char *ptr, head[18] = { 0,1,1,0,0,0,1,24,0,0,0,0,0/*wlo*/,0/*whi*/,0/*hlo*/,0/*hhi*/,8,0 };
//char palette[4*256];
char *fn = Bstrdup(filename);
char *fn = Xstrdup(filename);
# ifdef USE_OPENGL
int32_t j;
char *inversebuf;
@ -17464,9 +17385,8 @@ static int32_t screencapture_tga(const char *filename, char inverseit)
{
char c;
// 24bit
inversebuf = (char *)Bmalloc(xdim*ydim*3);
if (inversebuf)
{
inversebuf = (char *)Xmalloc(xdim*ydim*3);
bglReadPixels(0,0,xdim,ydim,GL_RGB,GL_UNSIGNED_BYTE,inversebuf);
j = xdim*ydim*3;
for (i=0; i<j; i+=3)
@ -17476,9 +17396,9 @@ static int32_t screencapture_tga(const char *filename, char inverseit)
inversebuf[i+2] = c;
}
Bfwrite(inversebuf, xdim*ydim, 3, fil);
Bfree(inversebuf);
}
}
else
# endif
{
@ -17657,7 +17577,7 @@ void setpolymost2dview(void)
void hash_init(hashtable_t *t)
{
hash_free(t);
t->items=(hashitem_t **)Bcalloc(1, t->size * sizeof(hashitem_t));
t->items=(hashitem_t **)Xcalloc(1, t->size * sizeof(hashitem_t));
}
void hash_free(hashtable_t *t)
@ -17722,8 +17642,8 @@ void hash_add(hashtable_t *t, const char *s, int32_t key, int32_t replace)
if (!cur)
{
cur = (hashitem_t *)Bcalloc(1,sizeof(hashitem_t));
cur->string = Bstrdup(s);
cur = (hashitem_t *)Xcalloc(1,sizeof(hashitem_t));
cur->string = Xstrdup(s);
cur->key = key;
cur->next = NULL;
t->items[code] = cur;
@ -17741,8 +17661,8 @@ void hash_add(hashtable_t *t, const char *s, int32_t key, int32_t replace)
}
while ((cur = cur->next));
cur = (hashitem_t *)Bcalloc(1,sizeof(hashitem_t));
cur->string = Bstrdup(s);
cur = (hashitem_t *)Xcalloc(1,sizeof(hashitem_t));
cur->string = Xstrdup(s);
cur->key = key;
cur->next = NULL;
prev->next = cur;

View file

@ -1070,8 +1070,8 @@ static void texdbg_realloc(uint32_t maxtexname)
newsize <<= 1;
// initprintf("texdebug: new size %u\n", newsize);
texnameused = Brealloc(texnameused, newsize>>3);
texnamefromwhere = Brealloc(texnamefromwhere, newsize*sizeof(uint32_t));
texnameused = Xrealloc(texnameused, newsize>>3);
texnamefromwhere = Xrealloc(texnamefromwhere, newsize*sizeof(uint32_t));
Bmemset(texnameused + (texnameallocsize>>3), 0, (newsize-texnameallocsize)>>3);
Bmemset(texnamefromwhere + texnameallocsize, 0, (newsize-texnameallocsize)*sizeof(uint32_t));

View file

@ -135,8 +135,7 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float
if (!hr)
{
// no replacement yet defined
hrn = (hicreplctyp *)Bcalloc(1,sizeof(hicreplctyp));
if (!hrn) return -1;
hrn = (hicreplctyp *)Xcalloc(1,sizeof(hicreplctyp));
hrn->palnum = palnum;
}
else hrn = hr;
@ -144,13 +143,7 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float
// store into hicreplc the details for this replacement
if (hrn->filename) Bfree(hrn->filename);
hrn->filename = Bstrdup(filen);
if (!hrn->filename)
{
if (hrn->skybox) return -1; // don't free the base structure if there's a skybox defined
if (hr == NULL) Bfree(hrn); // not yet a link in the chain
return -1;
}
hrn->filename = Xstrdup(filen);
hrn->ignore = 0;
hrn->alphacut = min(alphacut,1.0);
hrn->xscale = xscale;
@ -205,21 +198,14 @@ int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6])
if (!hr)
{
// no replacement yet defined
hrn = (hicreplctyp *)Bcalloc(1,sizeof(hicreplctyp));
if (!hrn) return -1;
hrn = (hicreplctyp *)Xcalloc(1,sizeof(hicreplctyp));
hrn->palnum = palnum;
}
else hrn = hr;
if (!hrn->skybox)
{
hrn->skybox = (struct hicskybox_t *)Bcalloc(1,sizeof(struct hicskybox_t));
if (!hrn->skybox)
{
if (hr == NULL) Bfree(hrn); // not yet a link in the chain
return -1;
}
hrn->skybox = (struct hicskybox_t *)Xcalloc(1,sizeof(struct hicskybox_t));
}
else
{
@ -233,16 +219,7 @@ int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6])
// store each face's filename
for (j=0; j<6; j++)
{
hrn->skybox->face[j] = Bstrdup(faces[j]);
if (!hrn->skybox->face[j])
{
for (--j; j>=0; --j) // free any previous faces
Bfree(hrn->skybox->face[j]);
Bfree(hrn->skybox);
hrn->skybox = NULL;
if (hr == NULL) Bfree(hrn);
return -1;
}
hrn->skybox->face[j] = Xstrdup(faces[j]);
}
hrn->skybox->ignore = 0;
if (hr == NULL)

View file

@ -74,12 +74,7 @@ static int32_t read_whole_file(const char *fn, char **retbufptr)
if (flen == 0)
return 5;
buf = (char *)Bmalloc(flen+1);
if (!buf)
{
kclose(fid);
return -1;
}
buf = (char *)Xmalloc(flen+1);
i = kread(fid, buf, flen);
kclose(fid);
@ -104,9 +99,7 @@ int L_CreateState(L_State *estate, const char *name, void (*StateSetupFunc)(lua_
{
lua_State *L;
estate->name = Bstrdup(name);
if (!estate->name)
return -1;
estate->name = Xstrdup(name);
L = estate->L = luaL_newstate();

View file

@ -18,11 +18,11 @@ int32_t lzwcompress(char *ucompbuf, int32_t ucompleng, char *compbuf)
#endif
char *nodev, *cptr, *eptr;
nodev = (char *)Bmalloc((ucompleng+256)*sizeof(uint8_t)); if (!nodev) return(0);
child = (int32_t *)Bmalloc((ucompleng+256)*sizeof(int32_t)); if (!child) { Bfree(nodev); return(0); }
sibly = (int32_t *)Bmalloc((ucompleng+256)*sizeof(int32_t)); if (!sibly) { Bfree(child); Bfree(nodev); return(0); }
nodev = (char *)Xmalloc((ucompleng+256)*sizeof(uint8_t));
child = (int32_t *)Xmalloc((ucompleng+256)*sizeof(int32_t));
sibly = (int32_t *)Xmalloc((ucompleng+256)*sizeof(int32_t));
#if USENEW
sibry = (int32_t *)Bmalloc((ucompleng+256)*sizeof(int32_t)); if (!sibry) { Bfree(sibly); Bfree(child); Bfree(nodev); return(0); }
sibry = (int32_t *)Xmalloc((ucompleng+256)*sizeof(int32_t));
#endif
for (i=255; i>=0; i--) { nodev[i] = i; child[i] = -1; }
@ -86,8 +86,8 @@ int32_t lzwuncompress(char *compbuf, int32_t compleng, char *ucompbuf, int32_t u
totnodes = LSWAPIB(((int32_t *)compbuf)[0]); if (totnodes <= 0 || totnodes >= ucompleng+256) return 0;
prefix = (int32_t *)Bmalloc(totnodes*sizeof(int32_t)); if (!prefix) return 0;
suffix = (char *)Bmalloc(totnodes*sizeof(uint8_t)); if (!suffix) { Bfree(prefix); return 0; }
prefix = (int32_t *)Xmalloc(totnodes*sizeof(int32_t));
suffix = (char *)Xmalloc(totnodes*sizeof(uint8_t));
numnodes = 256; bitcnt = (4<<3); nbits = 8; oneupnbits = (1<<8); hmask = ((oneupnbits>>1)-1);
do

View file

@ -257,7 +257,7 @@ int32_t md_loadmodel(const char *fn)
if (nextmodelid >= nummodelsalloced)
{
ml = (mdmodel_t **)Brealloc(models,(nummodelsalloced+MODELALLOCGROUP)*sizeof(void *)); if (!ml) return(-1);
ml = (mdmodel_t **)Xrealloc(models,(nummodelsalloced+MODELALLOCGROUP)*sizeof(void *));
models = ml; nummodelsalloced += MODELALLOCGROUP;
}
@ -369,8 +369,8 @@ int32_t md_defineanimation(int32_t modelid, const char *framestart, const char *
ma.fpssc = fpssc;
ma.flags = flags;
map = (mdanim_t *)Bmalloc(sizeof(mdanim_t));
if (!map) return(-4);
map = (mdanim_t *)Xmalloc(sizeof(mdanim_t));
Bmemcpy(map, &ma, sizeof(ma));
map->next = m->animations;
@ -463,17 +463,16 @@ int32_t md_thinoutmodel(int32_t modelid, uint8_t *usedframebitmap)
}
////// realloc & change "numframes" everywhere
// TODO: check if NULL
if (m->muladdframes)
m->muladdframes = Brealloc(m->muladdframes, 2*sizeof(point3d)*usedframes);
m->head.frames = Brealloc(m->head.frames, sizeof(md3frame_t)*usedframes);
m->muladdframes = Xrealloc(m->muladdframes, 2*sizeof(point3d)*usedframes);
m->head.frames = Xrealloc(m->head.frames, sizeof(md3frame_t)*usedframes);
for (surfi=0; surfi < m->head.numsurfs; surfi++)
{
m->head.surfs[surfi].numframes = usedframes;
// CAN'T do that because xyzn is offset from a larger block when loaded from md3:
// m->head.surfs[surfi].xyzn = Brealloc(m->head.surfs[surfi].xyzn, s->numverts*usedframes*sizeof(md3xyzn_t));
// m->head.surfs[surfi].xyzn = Xrealloc(m->head.surfs[surfi].xyzn, s->numverts*usedframes*sizeof(md3xyzn_t));
}
m->head.numframes = usedframes;
@ -505,8 +504,7 @@ int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32
break;
if (!sk)
{
sk = (mdskinmap_t *)Bcalloc(1,sizeof(mdskinmap_t));
if (!sk) return -4;
sk = (mdskinmap_t *)Xcalloc(1,sizeof(mdskinmap_t));
if (!skl) m->skinmap = sk;
else skl->next = sk;
@ -519,8 +517,7 @@ int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32
sk->param = param;
sk->specpower = specpower;
sk->specfactor = specfactor;
sk->fn = Bstrdup(skinfn);
if (!sk->fn) return(-4);
sk->fn = Xstrdup(skinfn);
return 0;
}
@ -583,7 +580,7 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t
int32_t r, g, b;
picfillen = kfilelength(filh);
picfil = (char *)Bmalloc(picfillen+1); if (!picfil) { return -1; }
picfil = (char *)Xmalloc(picfillen+1);
kread(filh, picfil, picfillen);
// tsizx/y = replacement texture's natural size
@ -603,8 +600,8 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t
ysiz = tsizy;
}
*osizx = tsizx; *osizy = tsizy;
pic = (coltype *)Bmalloc(xsiz*ysiz*sizeof(coltype));
if (!pic) { Bfree(picfil); return -1; }
pic = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype));
memset(pic,0,xsiz*ysiz*sizeof(coltype));
if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0))
@ -1084,7 +1081,7 @@ static void mdloadvbos(md3model_t *m)
{
int32_t i;
m->vbos = (GLuint *)Bmalloc(m->head.numsurfs * sizeof(GLuint));
m->vbos = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
bglGenBuffersARB(m->head.numsurfs, m->vbos);
i = 0;
@ -1110,7 +1107,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
int32_t ournumskins, ournumglcmds;
m = (md2model_t *)Bcalloc(1,sizeof(md2model_t)); if (!m) return(0);
m = (md2model_t *)Xcalloc(1,sizeof(md2model_t));
m->mdnum = 2; m->scale = .01f;
kread(fil,(char *)&head,sizeof(md2head_t));
@ -1135,10 +1132,10 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
m->numglcmds = head.numglcmds;
m->framebytes = head.framebytes;
m->frames = (char *)Bmalloc(m->numframes*m->framebytes); if (!m->frames) { Bfree(m); return(0); }
m->glcmds = (int32_t *)Bmalloc(ournumglcmds*sizeof(int32_t)); if (!m->glcmds) { Bfree(m->frames); Bfree(m); return(0); }
m->tris = (md2tri_t *)Bmalloc(head.numtris*sizeof(md2tri_t)); if (!m->tris) { Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->uv = (md2uv_t *)Bmalloc(head.numuv*sizeof(md2uv_t)); if (!m->uv) { Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->frames = (char *)Xmalloc(m->numframes*m->framebytes);
m->glcmds = (int32_t *)Xmalloc(ournumglcmds*sizeof(int32_t));
m->tris = (md2tri_t *)Xmalloc(head.numtris*sizeof(md2tri_t));
m->uv = (md2uv_t *)Xmalloc(head.numuv*sizeof(md2uv_t));
klseek(fil,head.ofsframes,SEEK_SET);
if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes)
@ -1199,10 +1196,10 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
if ((st[i] == '/') || (st[i] == '\\')) { i++; break; }
if (i<0) i=0;
st[i] = 0;
m->basepath = (char *)Bmalloc(i+1); if (!m->basepath) { Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->basepath = (char *)Xmalloc(i+1);
Bstrcpy(m->basepath, st);
m->skinfn = (char *)Bmalloc(ournumskins*64); if (!m->skinfn) { Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->skinfn = (char *)Xmalloc(ournumskins*64);
if (m->numskins > 0)
{
klseek(fil,head.ofsskins,SEEK_SET);
@ -1210,8 +1207,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
{ Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
}
m->texid = (GLuint *)Bcalloc(ournumskins, sizeof(GLuint) * (HICEFFECTMASK+1));
if (!m->texid) { Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m->texid = (GLuint *)Xcalloc(ournumskins, sizeof(GLuint) * (HICEFFECTMASK+1));
maxmodelverts = max(maxmodelverts, m->numverts);
maxmodeltris = max(maxmodeltris, head.numtris);
@ -1220,7 +1216,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
// the MD2 is now loaded internally - let's begin the MD3 conversion process
//OSD_Printf("Beginning md3 conversion.\n");
m3 = (md3model_t *)Bcalloc(1, sizeof(md3model_t)); if (!m3) { Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m3 = (md3model_t *)Xcalloc(1, sizeof(md3model_t));
m3->mdnum = 3; m3->texid = 0; m3->scale = m->scale;
m3->head.id = 0x33504449; m3->head.vers = 15;
@ -1244,8 +1240,8 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
m3->numskins = m3->head.numskins;
m3->numframes = m3->head.numframes;
m3->head.frames = (md3frame_t *)Bcalloc(m3->head.numframes, sizeof(md3frame_t)); if (!m3->head.frames) { Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m3->muladdframes = (point3d *)Bcalloc(m->numframes * 2, sizeof(point3d));
m3->head.frames = (md3frame_t *)Xcalloc(m3->head.numframes, sizeof(md3frame_t));
m3->muladdframes = (point3d *)Xcalloc(m->numframes * 2, sizeof(point3d));
f = (md2frame_t *)(m->frames);
@ -1263,7 +1259,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
m3->head.tags = NULL;
m3->head.surfs = (md3surf_t *)Bcalloc(1, sizeof(md3surf_t)); if (!m3->head.surfs) { Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
m3->head.surfs = (md3surf_t *)Xcalloc(1, sizeof(md3surf_t));
s = m3->head.surfs;
// model converting
@ -1280,9 +1276,9 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
s->shaders = NULL;
s->tris = (md3tri_t *)Bcalloc(head.numtris, sizeof(md3tri_t)); if (!s->tris) { Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
s->uv = (md3uv_t *)Bcalloc(s->numverts, sizeof(md3uv_t)); if (!s->uv) { Bfree(s->tris); Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
s->xyzn = (md3xyzn_t *)Bcalloc(s->numverts * m->numframes, sizeof(md3xyzn_t)); if (!s->xyzn) { Bfree(s->uv); Bfree(s->tris); Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
s->tris = (md3tri_t *)Xcalloc(head.numtris, sizeof(md3tri_t));
s->uv = (md3uv_t *)Xcalloc(s->numverts, sizeof(md3uv_t));
s->xyzn = (md3xyzn_t *)Xcalloc(s->numverts * m->numframes, sizeof(md3xyzn_t));
//memoryusage += (s->numverts * m->numframes * sizeof(md3xyzn_t));
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
@ -1336,26 +1332,23 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
{
mdskinmap_t *sk;
sk = (mdskinmap_t *)Bcalloc(1,sizeof(mdskinmap_t));
sk = (mdskinmap_t *)Xcalloc(1,sizeof(mdskinmap_t));
sk->palette = 0;
sk->skinnum = 0;
sk->surfnum = 0;
if (m->numskins > 0)
{
sk->fn = (char *)Bmalloc(strlen(m->basepath)+strlen(m->skinfn)+1);
sk->fn = (char *)Xmalloc(strlen(m->basepath)+strlen(m->skinfn)+1);
Bstrcpy(sk->fn, m->basepath);
Bstrcat(sk->fn, m->skinfn);
}
m3->skinmap = sk;
}
m3->indexes = (uint16_t *)Bmalloc(sizeof(uint16_t) * s->numtris);
m3->vindexes = (uint16_t *)Bmalloc(sizeof(uint16_t) * s->numtris * 3);
m3->maxdepths = (float *)Bmalloc(sizeof(float) * s->numtris);
if (!m3->indexes || !m3->vindexes || !m3->maxdepths)
QuitOnFatalError("OUT OF MEMORY in md2load!");
m3->indexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * s->numtris);
m3->vindexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * s->numtris * 3);
m3->maxdepths = (float *)Xmalloc(sizeof(float) * s->numtris);
m3->vbos = NULL;
@ -1421,7 +1414,7 @@ static md3model_t *md3load(int32_t fil)
md3model_t *m;
md3surf_t *s;
m = (md3model_t *)Bcalloc(1,sizeof(md3model_t)); if (!m) return(0);
m = (md3model_t *)Xcalloc(1,sizeof(md3model_t));
m->mdnum = 3; m->texid = 0; m->scale = .01f;
m->muladdframes = NULL;
@ -1442,19 +1435,19 @@ static md3model_t *md3load(int32_t fil)
ofsurf = m->head.ofssurfs;
klseek(fil,m->head.ofsframes,SEEK_SET); i = m->head.numframes*sizeof(md3frame_t);
m->head.frames = (md3frame_t *)Bmalloc(i); if (!m->head.frames) { Bfree(m); return(0); }
m->head.frames = (md3frame_t *)Xmalloc(i);
kread(fil,m->head.frames,i);
if (m->head.numtags == 0) m->head.tags = NULL;
else
{
klseek(fil,m->head.ofstags,SEEK_SET); i = m->head.numtags*sizeof(md3tag_t);
m->head.tags = (md3tag_t *)Bmalloc(i); if (!m->head.tags) { Bfree(m->head.frames); Bfree(m); return(0); }
m->head.tags = (md3tag_t *)Xmalloc(i);
kread(fil,m->head.tags,i);
}
klseek(fil,m->head.ofssurfs,SEEK_SET); i = m->head.numsurfs*sizeof(md3surf_t);
m->head.surfs = (md3surf_t *)Bmalloc(i); if (!m->head.surfs) { if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.frames); Bfree(m); return(0); }
m->head.surfs = (md3surf_t *)Xmalloc(i);
m->head.surfs[0].geometry = NULL; // for deferred polymer model postprocessing (else: crashes)
#if B_BIG_ENDIAN != 0
@ -1499,12 +1492,8 @@ static md3model_t *md3load(int32_t fil)
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
s->tris = (md3tri_t *)Bmalloc(leng[0]+leng[1]+leng[2]+leng[3]);
if (!s->tris)
{
for (surfi--; surfi>=0; surfi--) Bfree(m->head.surfs[surfi].tris);
if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.frames); Bfree(m); return(0);
}
s->tris = (md3tri_t *)Xmalloc(leng[0]+leng[1]+leng[2]+leng[3]);
s->shaders = (md3shader_t *)(((intptr_t)s->tris)+leng[0]);
s->uv = (md3uv_t *)(((intptr_t)s->shaders)+leng[1]);
s->xyzn = (md3xyzn_t *)(((intptr_t)s->uv)+leng[2]);
@ -1572,12 +1561,9 @@ static md3model_t *md3load(int32_t fil)
}
#endif
m->indexes = (uint16_t *)Bmalloc(sizeof(uint16_t) * maxtrispersurf);
m->vindexes = (uint16_t *)Bmalloc(sizeof(uint16_t) * maxtrispersurf * 3);
m->maxdepths = (float *)Bmalloc(sizeof(float) * maxtrispersurf);
if (!m->indexes || !m->vindexes || !m->maxdepths)
QuitOnFatalError("OUT OF MEMORY in md3load!");
m->indexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * maxtrispersurf);
m->vindexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * maxtrispersurf * 3);
m->maxdepths = (float *)Xmalloc(sizeof(float) * maxtrispersurf);
m->vbos = NULL;
@ -1812,12 +1798,9 @@ int md3postload_polymer(md3model_t *m)
initprintf("size %d (%d fr, %d v): md %s surf %d/%d\n", i, m->head.numframes, s->numverts,
m->head.nam, surfi, m->head.numsurfs);
#endif
s->geometry = (float *)Bcalloc(m->head.numframes * s->numverts * sizeof(float), 15);
s->geometry = (float *)Xcalloc(m->head.numframes * s->numverts * sizeof(float), 15);
numtris = (int *)Bcalloc(s->numverts, sizeof(int));
if (!s->geometry || !numtris)
QuitOnFatalError("OUT OF MEMORY in md3postload_polymer!");
numtris = (int *)Xcalloc(s->numverts, sizeof(int));
verti = 0;
while (verti < (m->head.numframes * s->numverts))
@ -2545,10 +2528,7 @@ uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, i
// Correct for GL's RGB order; also apply gamma here:
const coltype *const pic = (const coltype *)picbuf;
coltype *pic2 = (coltype *)Bmalloc(xsiz*ysiz*sizeof(coltype));
if (!pic2)
return (unsigned)-1;
coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype));
if (!is8bit)
{
@ -2597,7 +2577,7 @@ static int32_t getvox(int32_t x, int32_t y, int32_t z)
static void putvox(int32_t x, int32_t y, int32_t z, int32_t col)
{
if (vnum >= vmax) { vmax = max(vmax<<1,4096); vcol = (voxcol_t *)Brealloc(vcol,vmax*sizeof(voxcol_t)); }
if (vnum >= vmax) { vmax = max(vmax<<1,4096); vcol = (voxcol_t *)Xrealloc(vcol,vmax*sizeof(voxcol_t)); }
z += x*yzsiz + y*zsiz;
vcol[vnum].p = z; z = ((z*214013)&vcolhashsizm1);
@ -2805,7 +2785,7 @@ static voxmodel_t *vox2poly()
int32_t i, j, x, y, z, v, ov, oz = 0, cnt, sc, x0, y0, dx, dy,*bx0, *by0;
void (*daquad)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
gvox = (voxmodel_t *)Bmalloc(sizeof(voxmodel_t)); if (!gvox) return(0);
gvox = (voxmodel_t *)Xmalloc(sizeof(voxmodel_t));
memset(gvox,0,sizeof(voxmodel_t));
//x is largest dimension, y is 2nd largest dimension
@ -2813,7 +2793,7 @@ static voxmodel_t *vox2poly()
if ((x < y) && (x < z)) x = z; else if (y < z) y = z;
if (x < y) { z = x; x = y; y = z; }
shcntp = x; i = x*y*sizeof(int32_t);
shcntmal = (int32_t *)Bmalloc(i); if (!shcntmal) { Bfree(gvox); return(0); }
shcntmal = (int32_t *)Xmalloc(i);
memset(shcntmal,0,i); shcnt = &shcntmal[-shcntp-1];
gmaxx = gmaxy = garea = 0;
@ -2821,7 +2801,7 @@ static voxmodel_t *vox2poly()
for (i=0; i<7; i++) gvox->qfacind[i] = -1;
i = ((max(ysiz,zsiz)+1)<<2);
bx0 = (int32_t *)Bmalloc(i<<1); if (!bx0) { Bfree(gvox); return(0); }
bx0 = (int32_t *)Xmalloc(i<<1);
by0 = (int32_t *)(((intptr_t)bx0)+i);
for (cnt=0; cnt<2; cnt++)
@ -2867,8 +2847,7 @@ static voxmodel_t *vox2poly()
if (!cnt)
{
shp = (spoint2d *)Bmalloc(gvox->qcnt*sizeof(spoint2d));
if (!shp) { Bfree(bx0); Bfree(gvox); return(0); }
shp = (spoint2d *)Xmalloc(gvox->qcnt*sizeof(spoint2d));
sc = 0;
for (y=gmaxy; y; y--)
@ -2889,7 +2868,7 @@ skindidntfit:
mytexo5 = (gvox->mytexx>>5);
i = (((gvox->mytexx*gvox->mytexy+31)>>5)<<2);
zbit = (int32_t *)Bmalloc(i); if (!zbit) { Bfree(bx0); Bfree(gvox); Bfree(shp); return(0); }
zbit = (int32_t *)Xmalloc(i);
memset(zbit,0,i);
v = gvox->mytexx*gvox->mytexy;
@ -2931,11 +2910,8 @@ skindidntfit:
shp[z].x = x0; shp[z].y = y0; //Overwrite size with top-left location
}
gvox->quad = (voxrect_t *)Bmalloc(gvox->qcnt*sizeof(voxrect_t));
if (!gvox->quad) { Bfree(zbit); Bfree(shp); Bfree(bx0); Bfree(gvox); return(0); }
gvox->mytex = (int32_t *)Bmalloc(gvox->mytexx*gvox->mytexy*sizeof(int32_t));
if (!gvox->mytex) { Bfree(gvox->quad); Bfree(zbit); Bfree(shp); Bfree(bx0); Bfree(gvox); return(0); }
gvox->quad = (voxrect_t *)Xmalloc(gvox->qcnt*sizeof(voxrect_t));
gvox->mytex = (int32_t *)Xmalloc(gvox->mytexx*gvox->mytexy*sizeof(int32_t));
}
}
Bfree(shp); Bfree(zbit); Bfree(bx0);
@ -2961,14 +2937,14 @@ static int32_t loadvox(const char *filnam)
pal[255] = -1;
vcolhashsizm1 = 8192-1;
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
vcolhashead = (int32_t *)Xmalloc((vcolhashsizm1+1)*sizeof(int32_t));
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3)+1;
vbit = (int32_t *)Bmalloc(i); if (!vbit) { kclose(fil); return(-1); }
vbit = (int32_t *)Xmalloc(i);
memset(vbit,0,i);
tbuf = (char *)Bmalloc(zsiz*sizeof(uint8_t)); if (!tbuf) { kclose(fil); return(-1); }
tbuf = (char *)Xmalloc(zsiz*sizeof(uint8_t));
klseek(fil,12,SEEK_SET);
for (x=0; x<xsiz; x++)
@ -3021,7 +2997,7 @@ static int32_t loadkvx(const char *filnam)
ysizp1 = ysiz+1;
i = xsiz*ysizp1*sizeof(int16_t);
xyoffs = (uint16_t *)Bmalloc(i); if (!xyoffs) { kclose(fil); return(-1); }
xyoffs = (uint16_t *)Xmalloc(i);
kread(fil,xyoffs,i); for (i=i/sizeof(int16_t)-1; i>=0; i--) xyoffs[i] = B_LITTLE16(xyoffs[i]);
klseek(fil,-768,SEEK_END);
@ -3029,7 +3005,7 @@ static int32_t loadkvx(const char *filnam)
{ kread(fil,c,3); pal[i] = B_LITTLE32((((int32_t)c[0])<<18)+(((int32_t)c[1])<<10)+(((int32_t)c[2])<<2)+(i<<24)); }
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3)+1;
vbit = (int32_t *)Bmalloc(i); if (!vbit) { Bfree(xyoffs); kclose(fil); return(-1); }
vbit = (int32_t *)Xmalloc(i);
memset(vbit,0,i);
for (vcolhashsizm1=4096; vcolhashsizm1<(mip1leng>>1); vcolhashsizm1<<=1)
@ -3037,13 +3013,13 @@ static int32_t loadkvx(const char *filnam)
/* do nothing */
}
vcolhashsizm1--; //approx to numvoxs!
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { Bfree(xyoffs); kclose(fil); return(-1); }
vcolhashead = (int32_t *)Xmalloc((vcolhashsizm1+1)*sizeof(int32_t));
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
klseek(fil,28+((xsiz+1)<<2)+((ysizp1*xsiz)<<1),SEEK_SET);
i = kfilelength(fil)-ktell(fil);
tbuf = (char *)Bmalloc(i); if (!tbuf) { Bfree(xyoffs); kclose(fil); return(-1); }
tbuf = (char *)Xmalloc(i);
kread(fil,tbuf,i); kclose(fil);
cptr = tbuf;
@ -3081,15 +3057,14 @@ static int32_t loadkv6(const char *filnam)
kread(fil,&i,4); zpiv = (float)(B_LITTLE32(i));
kread(fil,&numvoxs,4); numvoxs = B_LITTLE32(numvoxs);
ylen = (uint16_t *)Bmalloc(xsiz*ysiz*sizeof(int16_t));
if (!ylen) { kclose(fil); return(-1); }
ylen = (uint16_t *)Xmalloc(xsiz*ysiz*sizeof(int16_t));
klseek(fil,32+(numvoxs<<3)+(xsiz<<2),SEEK_SET);
kread(fil,ylen,xsiz*ysiz*sizeof(int16_t)); for (i=xsiz*ysiz-1; i>=0; i--) ylen[i] = B_LITTLE16(ylen[i]);
klseek(fil,32,SEEK_SET);
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3)+1;
vbit = (int32_t *)Bmalloc(i); if (!vbit) { Bfree(ylen); kclose(fil); return(-1); }
vbit = (int32_t *)Xmalloc(i);
memset(vbit,0,i);
for (vcolhashsizm1=4096; vcolhashsizm1<numvoxs; vcolhashsizm1<<=1)
@ -3097,7 +3072,7 @@ static int32_t loadkv6(const char *filnam)
/* do nothing */
}
vcolhashsizm1--;
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { Bfree(ylen); kclose(fil); return(-1); }
vcolhashead = (int32_t *)Xmalloc((vcolhashsizm1+1)*sizeof(int32_t));
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
for (x=0; x<xsiz; x++)
@ -3136,16 +3111,16 @@ static int32_t loadvxl(const char *filnam)
zpiv = ((float)zsiz)*.5;
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
vbit = (int32_t *)Bmalloc(i); if (!vbit) { kclose(fil); return(-1); }
vbit = (int32_t *)Xmalloc(i);
memset(vbit,-1,i);
vcolhashsizm1 = 1048576-1;
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
vcolhashead = (int32_t *)Xmalloc((vcolhashsizm1+1)*sizeof(int32_t));
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
//Allocate huge buffer and load rest of file into it...
i = kfilelength(fil)-ktell(fil);
vbuf = (char *)Bmalloc(i); if (!vbuf) { kclose(fil); return(-1); }
vbuf = (char *)Xmalloc(i);
kread(fil,vbuf,i);
kclose(fil);
@ -3196,8 +3171,7 @@ voxmodel_t *voxload(const char *filnam)
vm->xpiv = xpiv; vm->ypiv = ypiv; vm->zpiv = zpiv;
vm->is8bit = is8bit;
vm->texid = (uint32_t *)Bcalloc(MAXPALOOKUPS,sizeof(uint32_t));
if (!vm->texid) { voxfree(vm); vm = 0; }
vm->texid = (uint32_t *)Xcalloc(MAXPALOOKUPS,sizeof(uint32_t));
}
if (shcntmal) { Bfree(shcntmal); shcntmal = 0; }
if (vbit) { Bfree(vbit); vbit = 0; }
@ -3399,8 +3373,8 @@ int32_t mddraw(const spritetype *tspr)
if (r_vbos && (r_vbocount > allocvbos))
{
indexvbos = (GLuint *)Brealloc(indexvbos, sizeof(GLuint) * r_vbocount);
vertvbos = (GLuint *)Brealloc(vertvbos, sizeof(GLuint) * r_vbocount);
indexvbos = (GLuint *)Xrealloc(indexvbos, sizeof(GLuint) * r_vbocount);
vertvbos = (GLuint *)Xrealloc(vertvbos, sizeof(GLuint) * r_vbocount);
bglGenBuffersARB(r_vbocount - allocvbos, &(indexvbos[allocvbos]));
bglGenBuffersARB(r_vbocount - allocvbos, &(vertvbos[allocvbos]));
@ -3423,8 +3397,8 @@ int32_t mddraw(const spritetype *tspr)
if (maxmodelverts > allocmodelverts)
{
point3d *vl = (point3d *)Brealloc(vertlist,sizeof(point3d)*maxmodelverts);
if (!vl) { OSD_Printf("ERROR: Not enough memory to allocate %d vertices!\n",maxmodelverts); return 0; }
point3d *vl = (point3d *)Xrealloc(vertlist,sizeof(point3d)*maxmodelverts);
vertlist = vl;
allocmodelverts = maxmodelverts;
}

View file

@ -166,7 +166,7 @@ int32_t OSD_RegisterCvar(const cvar_t *cvar)
}
}
cvars = (osdcvar_t *)Brealloc(cvars, (osdnumcvars + 1) * sizeof(osdcvar_t));
cvars = (osdcvar_t *)Xrealloc(cvars, (osdnumcvars + 1) * sizeof(osdcvar_t));
hash_add(&h_cvars, cvar->name, osdnumcvars, 1);
@ -572,7 +572,7 @@ static int32_t _internal_osdfunc_alias(const osdfuncparm_t *parm)
}
}
OSD_RegisterFunction(Bstrdup(parm->parms[0]),Bstrdup(parm->parms[1]),OSD_ALIAS);
OSD_RegisterFunction(Xstrdup(parm->parms[0]), Xstrdup(parm->parms[1]), OSD_ALIAS);
if (!osdexecscript)
OSD_Printf("%s\n",parm->raw);
return OSDCMD_OK;
@ -1608,7 +1608,7 @@ void OSD_Printf(const char *fmt, ...)
{
if (osdlog && (!logcutoff || linecnt < logcutoff))
{
chp = Bstrdup(tmpstr);
chp = Xstrdup(tmpstr);
Bfputs(OSD_StripColors(chp, tmpstr), osdlog);
Bprintf("%s", chp);
Bfree(chp);
@ -1809,8 +1809,7 @@ int32_t OSD_Dispatch(const char *cmd)
char *workbuf, *wp, *wtp, *state;
int32_t restart = 0;
workbuf = state = Bstrdup(cmd);
if (!workbuf) return -1;
workbuf = state = Xstrdup(cmd);
do
{
@ -1969,8 +1968,8 @@ static symbol_t *addnewsymbol(const char *name)
symbol_t *newsymb, *s, *t;
if (osdnumsymbols >= MAXSYMBOLS) return NULL;
newsymb = (symbol_t *)Bmalloc(sizeof(symbol_t));
if (!newsymb) { return NULL; }
newsymb = (symbol_t *)Xmalloc(sizeof(symbol_t));
Bmemset(newsymb, 0, sizeof(symbol_t));
// link it to the main chain
@ -2000,7 +1999,7 @@ static symbol_t *addnewsymbol(const char *name)
}
}
hash_add(&h_osd, name, osdnumsymbols, 1);
name = Bstrtolower(Bstrdup(name));
name = Bstrtolower(Xstrdup(name));
hash_add(&h_osd, name, osdnumsymbols, 1);
Bfree((void *)name);
osdsymbptrs[osdnumsymbols++] = newsymb;
@ -2028,7 +2027,7 @@ static symbol_t *findsymbol(const char *name, symbol_t *startingat)
static symbol_t *findexactsymbol(const char *name)
{
int32_t i;
char *lname = Bstrdup(name);
char *lname = Xstrdup(name);
if (!symbols) return NULL;
i = hash_find(&h_osd,lname);

View file

@ -1645,7 +1645,7 @@ void polymer_texinvalidate(void)
void polymer_definehighpalookup(char basepalnum, char palnum, char *data)
{
prhighpalookups[basepalnum][palnum].data = (char *)Bmalloc(PR_HIGHPALOOKUP_DATA_SIZE);
prhighpalookups[basepalnum][palnum].data = (char *)Xmalloc(PR_HIGHPALOOKUP_DATA_SIZE);
Bmemcpy(prhighpalookups[basepalnum][palnum].data, data, PR_HIGHPALOOKUP_DATA_SIZE);
}
@ -1705,8 +1705,8 @@ static void polymer_displayrooms(int16_t dacursectnum)
mirrorcount = 0;
localsectormasks = (int16_t *)Bmalloc(sizeof(int16_t) * numsectors);
localsectormaskcount = (int16_t *)Bcalloc(sizeof(int16_t), 1);
localsectormasks = (int16_t *)Xmalloc(sizeof(int16_t) * numsectors);
localsectormaskcount = (int16_t *)Xcalloc(sizeof(int16_t), 1);
cursectormasks = localsectormasks;
cursectormaskcount = localsectormaskcount;
@ -2271,23 +2271,14 @@ static int32_t polymer_initsector(int16_t sectnum)
if (pr_verbosity >= 2) OSD_Printf("PR : Initializing sector %i...\n", sectnum);
sec = &sector[sectnum];
s = (_prsector *)Bcalloc(1, sizeof(_prsector));
if (s == NULL)
{
if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize sector %i : Bmalloc failed.\n", sectnum);
return (0);
}
s = (_prsector *)Xcalloc(1, sizeof(_prsector));
s->verts = (GLdouble *)Bcalloc(sec->wallnum, sizeof(GLdouble) * 3);
s->floor.buffer = (GLfloat *)Bcalloc(sec->wallnum, sizeof(GLfloat) * 5);
s->verts = (GLdouble *)Xcalloc(sec->wallnum, sizeof(GLdouble) * 3);
s->floor.buffer = (GLfloat *)Xcalloc(sec->wallnum, sizeof(GLfloat) * 5);
s->floor.vertcount = sec->wallnum;
s->ceil.buffer = (GLfloat *)Bcalloc(sec->wallnum, sizeof(GLfloat) * 5);
s->ceil.buffer = (GLfloat *)Xcalloc(sec->wallnum, sizeof(GLfloat) * 5);
s->ceil.vertcount = sec->wallnum;
if ((s->verts == NULL) || (s->floor.buffer == NULL) || (s->ceil.buffer == NULL))
{
if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize geometry of sector %i : Bmalloc failed.\n", sectnum);
return (0);
}
bglGenBuffersARB(1, &s->floor.vbo);
bglGenBuffersARB(1, &s->ceil.vbo);
bglGenBuffersARB(1, &s->floor.ivbo);
@ -2615,8 +2606,8 @@ void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector)
{
if (pr_verbosity >= 2) OSD_Printf("PR : Indice overflow, extending the indices list... !\n");
s->indicescount++;
s->floor.indices = (GLushort *)Brealloc(s->floor.indices, s->indicescount * sizeof(GLushort));
s->ceil.indices = (GLushort *)Brealloc(s->ceil.indices, s->indicescount * sizeof(GLushort));
s->floor.indices = (GLushort *)Xrealloc(s->floor.indices, s->indicescount * sizeof(GLushort));
s->ceil.indices = (GLushort *)Xrealloc(s->ceil.indices, s->indicescount * sizeof(GLushort));
}
s->ceil.indices[s->curindice] = (intptr_t)vertex;
s->curindice++;
@ -2640,8 +2631,8 @@ static int32_t polymer_buildfloor(int16_t sectnum)
if (s->floor.indices == NULL)
{
s->indicescount = (max(3, sec->wallnum) - 2) * 3;
s->floor.indices = (GLushort *)Bcalloc(s->indicescount, sizeof(GLushort));
s->ceil.indices = (GLushort *)Bcalloc(s->indicescount, sizeof(GLushort));
s->floor.indices = (GLushort *)Xcalloc(s->indicescount, sizeof(GLushort));
s->ceil.indices = (GLushort *)Xcalloc(s->indicescount, sizeof(GLushort));
}
s->curindice = 0;
@ -2783,21 +2774,16 @@ static int32_t polymer_initwall(int16_t wallnum)
if (pr_verbosity >= 2) OSD_Printf("PR : Initializing wall %i...\n", wallnum);
w = (_prwall *)Bcalloc(1, sizeof(_prwall));
if (w == NULL)
{
if (pr_verbosity >= 1) OSD_Printf("PR : Cannot initialize wall %i : Bmalloc failed.\n", wallnum);
return (0);
}
w = (_prwall *)Xcalloc(1, sizeof(_prwall));
if (w->mask.buffer == NULL) {
w->mask.buffer = (GLfloat *)Bmalloc(4 * sizeof(GLfloat) * 5);
w->mask.buffer = (GLfloat *)Xmalloc(4 * sizeof(GLfloat) * 5);
w->mask.vertcount = 4;
}
if (w->bigportal == NULL)
w->bigportal = (GLfloat *)Bmalloc(4 * sizeof(GLfloat) * 5);
w->bigportal = (GLfloat *)Xmalloc(4 * sizeof(GLfloat) * 5);
if (w->cap == NULL)
w->cap = (GLfloat *)Bmalloc(4 * sizeof(GLfloat) * 3);
w->cap = (GLfloat *)Xmalloc(4 * sizeof(GLfloat) * 3);
bglGenBuffersARB(1, &w->wall.vbo);
bglGenBuffersARB(1, &w->over.vbo);
@ -2897,7 +2883,7 @@ static void polymer_updatewall(int16_t wallnum)
}
if (w->wall.buffer == NULL) {
w->wall.buffer = (GLfloat *)Bcalloc(4, sizeof(GLfloat) * 5); // XXX
w->wall.buffer = (GLfloat *)Xcalloc(4, sizeof(GLfloat) * 5); // XXX
w->wall.vertcount = 4;
}
@ -3101,7 +3087,7 @@ static void polymer_updatewall(int16_t wallnum)
if ((overwall) || (wal->cstat & 16) || (wal->cstat & 32))
{
if (w->over.buffer == NULL) {
w->over.buffer = (GLfloat *)Bmalloc(4 * sizeof(GLfloat) * 5);
w->over.buffer = (GLfloat *)Xmalloc(4 * sizeof(GLfloat) * 5);
w->over.vertcount = 4;
}
@ -3588,15 +3574,9 @@ void polymer_updatesprite(int32_t snum)
if (prsprites[tspr->owner] == NULL)
{
prsprites[tspr->owner] = (_prsprite *) Bcalloc(sizeof(_prsprite), 1);
prsprites[tspr->owner] = (_prsprite *)Xcalloc(sizeof(_prsprite), 1);
if (prsprites[tspr->owner] == NULL)
{
if (pr_verbosity >= 1) OSD_Printf_nowarn("PR : Cannot initialize sprite %i : Bmalloc failed.\n", TrackerCast(tspr->owner));
return;
}
prsprites[tspr->owner]->plane.buffer = (GLfloat *) Bcalloc(4, sizeof(GLfloat) * 5); // XXX
prsprites[tspr->owner]->plane.buffer = (GLfloat *)Xcalloc(4, sizeof(GLfloat) * 5); // XXX
prsprites[tspr->owner]->plane.vertcount = 4;
}
@ -4487,9 +4467,9 @@ static void polymer_loadmodelvbos(md3model_t* m)
int32_t i;
md3surf_t *s;
m->indices = (GLuint *)Bmalloc(m->head.numsurfs * sizeof(GLuint));
m->texcoords = (GLuint *)Bmalloc(m->head.numsurfs * sizeof(GLuint));
m->geometry = (GLuint *)Bmalloc(m->head.numsurfs * sizeof(GLuint));
m->indices = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
m->texcoords = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
m->geometry = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
bglGenBuffersARB(m->head.numsurfs, m->indices);
bglGenBuffersARB(m->head.numsurfs, m->texcoords);
@ -4587,7 +4567,7 @@ static void polymer_getbuildmaterial(_prmaterial* material, int16_t tile
if (pr_artmapping && polymer_eligible_for_artmap(tilenum, pth)) {
if (!prartmaps[tilenum]) {
char *tilebuffer = (char *)waloff[tilenum];
char *tempbuffer = (char *)Bmalloc(tilesizx[tilenum] * tilesizy[tilenum]);
char *tempbuffer = (char *)Xmalloc(tilesizx[tilenum] * tilesizy[tilenum]);
int i, j, k;
i = k = 0;
@ -5485,7 +5465,7 @@ out:
}
oldhead = prlights[lighti].planelist;
prlights[lighti].planelist = (_prplanelist *)Bmalloc(sizeof(_prplanelist));
prlights[lighti].planelist = (_prplanelist *)Xmalloc(sizeof(_prplanelist));
prlights[lighti].planelist->n = oldhead;
prlights[lighti].planelist->plane = plane;
@ -5897,7 +5877,7 @@ static void polymer_initrendertargets(int32_t count)
ocount = count;
//////////
prrts = (_prrt *)Bcalloc(count, sizeof(_prrt));
prrts = (_prrt *)Xcalloc(count, sizeof(_prrt));
i = 0;
while (i < count)

View file

@ -895,7 +895,7 @@ static void texture_setup(int32_t dameth)
}
}
int32_t gloadtile_art(int32_t dapic, int32_t dapal, int32_t dashade, int32_t dameth, pthtyp *pth, int32_t doalloc)
void gloadtile_art(int32_t dapic, int32_t dapal, int32_t dashade, int32_t dameth, pthtyp *pth, int32_t doalloc)
{
coltype *pic;
int32_t xsiz, ysiz;
@ -924,9 +924,7 @@ int32_t gloadtile_art(int32_t dapic, int32_t dapal, int32_t dashade, int32_t dam
}
}
pic = (coltype *)Bmalloc(xsiz*ysiz*sizeof(coltype));
if (!pic)
return 1;
pic = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype));
if (!waloff[dapic])
{
@ -1020,19 +1018,13 @@ int32_t gloadtile_art(int32_t dapic, int32_t dapal, int32_t dashade, int32_t dam
// make the final texture with fullbright pixels.
fullbrightloadingpass = 1;
pth->ofb = (pthtyp *)Bcalloc(1,sizeof(pthtyp));
if (!pth->ofb)
return 1;
pth->ofb = (pthtyp *)Xcalloc(1,sizeof(pthtyp));
pth->flags |= PTH_HASFULLBRIGHT;
if (gloadtile_art(dapic, dapal, 0, dameth, pth->ofb, 1))
return 1;
gloadtile_art(dapic, dapal, 0, dameth, pth->ofb, 1);
fullbrightloadingpass = 0;
}
return 0;
}
int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp *hicr,
@ -1100,7 +1092,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
if ((filh = kopen4load(fn, 0)) < 0) return -1;
picfil = (char *)Bmalloc(picfillen+1); if (!picfil) { kclose(filh); return 1; }
picfil = (char *)Xmalloc(picfillen+1);
if (kread(filh, picfil, picfillen) != picfillen)
initprintf("warning: didn't fully read %s\n", fn);
// prevent
@ -1127,7 +1119,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
xsiz = tsizx;
ysiz = tsizy;
}
pic = (coltype *)Bcalloc(xsiz,ysiz*sizeof(coltype)); if (!pic) { Bfree(picfil); return 1; }
pic = (coltype *)Xcalloc(xsiz,ysiz*sizeof(coltype));
startticks = getticks();
@ -4631,9 +4623,9 @@ static void tessectrap(const float *px, const float *py, const int32_t *point2,
if (numpoints+16 > allocpoints) //16 for safety
{
allocpoints = numpoints+16;
rst = (raster *)Brealloc(rst,allocpoints*sizeof(raster));
slist = (int32_t *)Brealloc(slist,allocpoints*sizeof(int32_t));
npoint2 = (int32_t *)Brealloc(npoint2,allocpoints*sizeof(int32_t));
rst = (raster *)Xrealloc(rst,allocpoints*sizeof(raster));
slist = (int32_t *)Xrealloc(slist,allocpoints*sizeof(int32_t));
npoint2 = (int32_t *)Xrealloc(npoint2,allocpoints*sizeof(int32_t));
}
//Remove unnecessary collinear points:
@ -4905,13 +4897,7 @@ static int32_t gen_font_glyph_tex(void)
bglGenTextures(1,&polymosttext);
if (!polymosttext) return -1;
tbuf = (char *)Bmalloc(256*128);
if (!tbuf)
{
bglDeleteTextures(1,&polymosttext);
polymosttext = 0;
return -1;
}
tbuf = (char *)Xmalloc(256*128);
Bmemset(tbuf, 0, 256*128);
cptr = (char *)textfont;

View file

@ -213,7 +213,7 @@ void scriptfile_preparse(scriptfile *sf, char *tx, int32_t flen)
}
sf->linenum = numcr;
sf->lineoffs = (int32_t *)Bmalloc(sf->linenum*sizeof(int32_t));
sf->lineoffs = (int32_t *)Xmalloc(sf->linenum*sizeof(int32_t));
//Preprocess file for comments (// and /*...*/, and convert all whitespace to single spaces)
nflen = 0; ws = 0; cs = 0; numcr = 0; inquote = 0;
@ -272,20 +272,9 @@ scriptfile *scriptfile_fromfile(const char *fn)
if (fp<0) return NULL;
flen = kfilelength(fp);
tx = (char *) Bmalloc(flen + 2);
if (!tx)
{
kclose(fp);
return NULL;
}
tx = (char *)Xmalloc(flen + 2);
sf = (scriptfile *) Bmalloc(sizeof(scriptfile));
if (!sf)
{
kclose(fp);
Bfree(tx);
return NULL;
}
sf = (scriptfile *)Xmalloc(sizeof(scriptfile));
kread(fp, tx, flen);
tx[flen] = tx[flen+1] = 0;
@ -293,7 +282,7 @@ scriptfile *scriptfile_fromfile(const char *fn)
kclose(fp);
scriptfile_preparse(sf,tx,flen);
sf->filename = Bstrdup(fn);
sf->filename = Xstrdup(fn);
return sf;
}
@ -308,15 +297,9 @@ scriptfile *scriptfile_fromstring(const char *string)
flen = strlen(string);
tx = (char *) Bmalloc(flen + 2);
if (!tx) return NULL;
tx = (char *)Xmalloc(flen + 2);
sf = (scriptfile *) Bmalloc(sizeof(scriptfile));
if (!sf)
{
Bfree(tx);
return NULL;
}
sf = (scriptfile *)Xmalloc(sizeof(scriptfile));
Bmemcpy(tx, string, flen);
tx[flen] = tx[flen+1] = 0;
@ -357,7 +340,7 @@ static char *getsymbtabspace(int32_t reqd)
if (symbtablength + reqd > symbtaballoclength)
{
for (i=max(symbtaballoclength,SYMBTABSTARTSIZE); symbtablength+reqd>i; i<<=1);
np = (char *)Brealloc(symbtab, i); if (!np) return NULL;
np = (char *)Xrealloc(symbtab, i);
symbtab = np; symbtaballoclength = i;
}

View file

@ -11,7 +11,6 @@
#include "xxhash.h"
#define CLEAR_GL_ERRORS() while(bglGetError() != GL_NO_ERROR) { }
#define REALLOC_OR_FAIL(ptr, size, type) { ptr = (type *)Brealloc(ptr, size); if (!ptr) goto failure; }
#define TEXCACHE_FREEBUFS() { Bfree(pic), Bfree(packbuf), Bfree(midbuf); }
globaltexcache texcache;
@ -78,8 +77,7 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3
}
pth = (pthtyp *)Bcalloc(1,sizeof(pthtyp));
if (!pth) return NULL;
pth = (pthtyp *)Xcalloc(1,sizeof(pthtyp));
// possibly fetch an already loaded multitexture :_)
if (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS))
@ -131,22 +129,15 @@ tryart:
if (pth->flags & PTH_INVALIDATED)
{
pth->flags &= ~PTH_INVALIDATED;
if (gloadtile_art(dapicnum,dapalnum,dashade,dameth,pth,0))
return NULL; //reload tile (for animations)
gloadtile_art(dapicnum, dapalnum, dashade, dameth, pth, 0);
}
return(pth);
}
pth = (pthtyp *)Bcalloc(1,sizeof(pthtyp));
if (!pth) return NULL;
pth = (pthtyp *)Xcalloc(1,sizeof(pthtyp));
if (gloadtile_art(dapicnum,dapalnum,dashade,dameth,pth,1))
{
Bfree(pth);
return NULL;
}
gloadtile_art(dapicnum,dapalnum,dashade,dameth,pth,1);
pth->next = texcache.list[j];
texcache.list[j] = pth;
@ -240,7 +231,7 @@ void texcache_init(void)
texcache_clearmemcache();
texcache_freeptrs();
texcache.currentindex = texcache.firstindex = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex));
texcache.currentindex = texcache.firstindex = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
texcache.numentries = 0;
// Bmemset(&firstcacheindex, 0, sizeof(texcacheindex));
@ -373,7 +364,7 @@ int32_t texcache_loadoffsets(void)
Bstrncpyz(texcache.currentindex->name, fname, BMAX_PATH);
texcache.currentindex->offset = foffset;
texcache.currentindex->len = fsize;
texcache.currentindex->next = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex));
texcache.currentindex->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
hash_add(&texcache.hashes, fname, texcache.numentries, 1);
texcache.ptrs[texcache.numentries++] = texcache.currentindex;
texcache.currentindex = texcache.currentindex->next;
@ -569,10 +560,10 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect,
if (alloclen < miplen)
{
REALLOC_OR_FAIL(pic, miplen, char);
pic = (char *)Xrealloc(pic, miplen);
alloclen = miplen;
REALLOC_OR_FAIL(packbuf, alloclen+400, char);
REALLOC_OR_FAIL(midbuf, miplen, void);
packbuf = (char *)Xrealloc(packbuf, alloclen+400);
midbuf = (void *)Xrealloc(midbuf, miplen);
}
bglGetCompressedTexImageARB(GL_TEXTURE_2D, level, pic); WRITEX_FAIL_ON_ERROR();
@ -598,7 +589,7 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect,
Bstrcpy(t->name, cachefn);
t->offset = offset;
t->len = Blseek(texcache.filehandle, 0, BSEEK_CUR) - t->offset;
t->next = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex));
t->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
hash_add(&texcache.hashes, cachefn, texcache.numentries, 0);
texcache.ptrs[texcache.numentries++] = t;
@ -670,10 +661,10 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int3
if (alloclen < pict.size)
{
REALLOC_OR_FAIL(pic, pict.size, char);
pic = (char *)Xrealloc(pic, pict.size);
alloclen = pict.size;
REALLOC_OR_FAIL(packbuf, alloclen+16, char);
REALLOC_OR_FAIL(midbuf, pict.size, void);
packbuf = (char *)Xrealloc(packbuf, alloclen+16);
midbuf = (void *)Xrealloc(midbuf, pict.size);
}
if (dedxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf,
@ -707,10 +698,6 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int3
TEXCACHE_FREEBUFS();
return 0;
failure:
TEXCACHE_FREEBUFS();
return TEXCACHERR_OUTOFMEMORY;
}
int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, int32_t *xsiz, int32_t *ysiz)

View file

@ -406,13 +406,11 @@ static void create_compressed_block(int32_t idx, const void *srcdata, uint32_t s
uint32_t j;
// allocate
mapstate->sws[idx] = (char *)Bmalloc(4 + size + QADDNSZ);
if (!mapstate->sws[idx]) { initprintf("OUT OF MEM in undo/redo\n"); osdcmd_quit(NULL); }
mapstate->sws[idx] = (char *)Xmalloc(4 + size + QADDNSZ);
// compress & realloc
j = LZ4_compress((const char*)srcdata, mapstate->sws[idx]+4, size);
mapstate->sws[idx] = (char *)Brealloc(mapstate->sws[idx], 4 + j);
if (!mapstate->sws[idx]) { initprintf("COULD not realloc in undo/redo\n"); osdcmd_quit(NULL); }
mapstate->sws[idx] = (char *)Xrealloc(mapstate->sws[idx], 4 + j);
// write refcount
*(int32_t *)mapstate->sws[idx] = 1;
@ -465,7 +463,7 @@ void create_map_snapshot(void)
map_revision = 1;
mapstate = (mapundo_t *)Bcalloc(1, sizeof(mapundo_t));
mapstate = (mapundo_t *)Xcalloc(1, sizeof(mapundo_t));
mapstate->revision = map_revision;
mapstate->prev = mapstate->next = NULL;
}
@ -476,7 +474,7 @@ void create_map_snapshot(void)
// now, have no successors
// calloc because not everything may be set in the following:
mapstate->next = (mapundo_t *)Bcalloc(1, sizeof(mapundo_t));
mapstate->next = (mapundo_t *)Xcalloc(1, sizeof(mapundo_t));
mapstate->next->prev = mapstate;
mapstate = mapstate->next;
@ -515,11 +513,9 @@ void create_map_snapshot(void)
if (!try_match_with_prev(2, Numsprites, temphash))
{
int32_t i = 0;
spritetype *const tspri = (spritetype *)Bmalloc(Numsprites*sizeof(spritetype) + 4);
spritetype *const tspri = (spritetype *)Xmalloc(Numsprites*sizeof(spritetype) + 4);
spritetype *spri = tspri;
if (!tspri) { initprintf("OUT OF MEM in undo/redo (2)\n"); osdcmd_quit(NULL); }
for (j=0; j<MAXSPRITES && i < Numsprites; j++)
if (sprite[j].statnum != MAXSTATUS)
{
@ -805,7 +801,7 @@ int32_t taglab_load(const char *filename, int32_t flags)
len = kfilelength(fil);
filebuf = (char *)Bmalloc(len+1);
filebuf = (char *)Xmalloc(len+1);
if (!filebuf)
{
kclose(fil);
@ -948,7 +944,7 @@ int32_t taglab_add(const char *label, int16_t tag)
if (!diddel)
g_taglab.numlabels++;
g_taglab.label[tag] = Bstrdup(buf);
g_taglab.label[tag] = Xstrdup(buf);
//initprintf("added %s %d to hash\n", g_taglab.label[tag], tag);
hash_add(&g_taglab.hashtab, g_taglab.label[tag], tag, 1);
@ -1924,9 +1920,8 @@ static void ReadHelpFile(const char *name)
return;
}
helppage=(helppage_t **)Bmalloc(IHELP_INITPAGES * sizeof(helppage_t *));
helppage=(helppage_t **)Xmalloc(IHELP_INITPAGES * sizeof(helppage_t *));
numallocpages=IHELP_INITPAGES;
if (!helppage) goto HELPFILE_ERROR;
i=0;
while (!Bfeof(fp) && !ferror(fp))
@ -1944,8 +1939,8 @@ static void ReadHelpFile(const char *name)
if (Bfeof(fp) || charsread<=0) break;
hp=(helppage_t *)Bcalloc(1,sizeof(helppage_t) + IHELP_INITLINES*80);
if (!hp) goto HELPFILE_ERROR;
hp=(helppage_t *)Xcalloc(1,sizeof(helppage_t) + IHELP_INITLINES*80);
hp->numlines = IHELP_INITLINES;
if (charsread == 79 && tempbuf[78]!='\n') skip=1;
@ -1955,8 +1950,7 @@ static void ReadHelpFile(const char *name)
{
if (j >= hp->numlines)
{
hp=(helppage_t *)Brealloc(hp, sizeof(helppage_t) + 2*hp->numlines*80);
if (!hp) goto HELPFILE_ERROR;
hp=(helppage_t *)Xrealloc(hp, sizeof(helppage_t) + 2*hp->numlines*80);
hp->numlines *= 2;
}
@ -1988,31 +1982,23 @@ static void ReadHelpFile(const char *name)
}
while (!newpage(tempbuf) && !Bfeof(fp) && charsread>0);
hp=(helppage_t *)Brealloc(hp, sizeof(helppage_t) + j*80);
if (!hp) goto HELPFILE_ERROR;
hp=(helppage_t *)Xrealloc(hp, sizeof(helppage_t) + j*80);
hp->numlines=j;
if (i >= numallocpages)
{
helppage = (helppage_t **)Brealloc(helppage, 2*numallocpages*sizeof(helppage_t *));
helppage = (helppage_t **)Xrealloc(helppage, 2*numallocpages*sizeof(helppage_t *));
numallocpages *= 2;
if (!helppage) goto HELPFILE_ERROR;
}
helppage[i] = hp;
i++;
}
helppage =(helppage_t **) Brealloc(helppage, i*sizeof(helppage_t *));
if (!helppage) goto HELPFILE_ERROR;
helppage =(helppage_t **)Xrealloc(helppage, i*sizeof(helppage_t *));
numhelppages = i;
Bfclose(fp);
return;
HELPFILE_ERROR:
Bfclose(fp);
initprintf("ReadHelpFile(): ERROR allocating memory.\n");
return;
}
// why can't MSVC allocate an array of variable size?!
@ -2311,9 +2297,8 @@ static int32_t sort_sounds(int32_t how)
n = g_numsounds;
src = source = g_sndnum;
dest = (int16_t *)Bmalloc(sizeof(int16_t) * n);
dest = (int16_t *)Xmalloc(sizeof(int16_t) * n);
dst = dest;
if (!dest) return -1;
switch (how)
{
@ -3727,8 +3712,7 @@ static int32_t OnSaveTileGroup(void)
Bfprintf(fp, "tilegroup \"%s\"" OURNEWL"{" OURNEWL, name);
Bfprintf(fp, TTAB "hotkey \"%c\"" OURNEWL OURNEWL, hotkey);
if (!(s_TileGroups[tile_groups].pIds = (int32_t *)Bmalloc(n * sizeof(s_TileGroups[tile_groups].pIds[0]))))
TMPERRMSG_RETURN("Out of memory.");
s_TileGroups[tile_groups].pIds = (int32_t *)Xmalloc(n * sizeof(s_TileGroups[tile_groups].pIds[0]));
j = 0;
// tileranges for consecutive runs of 3 or more tiles
@ -3812,11 +3796,7 @@ static int32_t OnSaveTileGroup(void)
Bfclose(fp);
if (!(s_TileGroups[tile_groups].szText = Bstrdup(name)))
{
Bfree(s_TileGroups[tile_groups].pIds);
TMPERRMSG_RETURN("Out of memory.");
}
s_TileGroups[tile_groups].szText = Xstrdup(name);
s_TileGroups[tile_groups].nIds = n;
s_TileGroups[tile_groups].key1 = Btoupper(hotkey);
@ -4486,8 +4466,7 @@ ENDFOR1:
sprite[startspr].xoffset = -picanm[t].xofs;
sprite[startspr].yoffset = -picanm[t].yofs;
spritenums = (int16_t *)Bmalloc(stackallocsize * sizeof(int16_t));
if (!spritenums) goto ERROR_NOMEMORY;
spritenums = (int16_t *)Xmalloc(stackallocsize * sizeof(int16_t));
cursor = insertsprite(sprite[startspr].sectnum,0);
if (cursor < 0) goto ERROR_TOOMANYSPRITES;
@ -4623,8 +4602,7 @@ ENDFOR1:
if (numletters >= stackallocsize)
{
stackallocsize *= 2;
spritenums = (int16_t *)Brealloc(spritenums, stackallocsize*sizeof(int16_t));
if (!spritenums) goto ERROR_NOMEMORY;
spritenums = (int16_t *)Xrealloc(spritenums, stackallocsize*sizeof(int16_t));
}
spritenums[numletters++] = i;
}
@ -4690,9 +4668,7 @@ ERROR_TOOMANYSPRITES:
if (cursor < 0) message("Too many sprites in map!");
else deletesprite(cursor);
ERROR_NOMEMORY:
if (spritenums) Bfree(spritenums);
else message("Out of memory!");
Bfree(spritenums);
clearkeys();
@ -8584,8 +8560,8 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
char clipshape[16] = "_clipshape0.map";
clipshape[10] = j;
g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(clipshape);
g_clipMapFiles = (char **) Xrealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(clipshape);
++g_clipMapFilesNum;
}
#endif
@ -8593,14 +8569,14 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
if (argc <= 1)
return;
lengths = (int32_t *)Bmalloc(argc*sizeof(int32_t));
lengths = (int32_t *)Xmalloc(argc*sizeof(int32_t));
for (j=1; j<argc; j++)
{
lengths[j] = Bstrlen(argv[j]);
maxlen += lengths[j];
}
testplay_addparam = (char *)Bmalloc(maxlen+argc);
testplay_addparam = (char *)Xmalloc(maxlen+argc);
testplay_addparam[0] = 0;
j = 0;
@ -8924,7 +8900,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
if (j > 0)
{
testplay_addparam[j-1] = 0;
testplay_addparam = (char *)Brealloc(testplay_addparam, j*sizeof(char));
testplay_addparam = (char *)Xrealloc(testplay_addparam, j*sizeof(char));
}
else
{
@ -9089,9 +9065,9 @@ static int32_t osdcmd_testplay_addparam(const osdfuncparm_t *parm)
if (slen > 0)
{
if (!testplay_addparam)
testplay_addparam = (char *)Bmalloc(slen+1);
testplay_addparam = (char *)Xmalloc(slen+1);
else
testplay_addparam = (char *)Brealloc(testplay_addparam, slen+1);
testplay_addparam = (char *)Xrealloc(testplay_addparam, slen+1);
Bmemcpy(testplay_addparam, parm->parms[0], slen);
testplay_addparam[slen] = 0;
@ -9402,7 +9378,7 @@ static void SaveInHistory(const char *commandstr)
{
if (scripthist[scripthistend])
Bfree(scripthist[scripthistend]);
scripthist[scripthistend] = Bstrdup(commandstr);
scripthist[scripthistend] = Xstrdup(commandstr);
scripthistend++;
scripthistend %= SCRIPTHISTSIZ;
}
@ -9495,8 +9471,8 @@ static int32_t osdcmd_do(const osdfuncparm_t *parm)
ofs = 2*(parm->numparms>0); // true if "do" command
slen = Bstrlen(parm->raw+ofs);
tp = (char *)Bmalloc(slen+2);
if (!tp) goto OUTOFMEM;
tp = (char *)Xmalloc(slen+2);
Bmemcpy(tp, parm->raw+ofs, slen);
// M32script call from 'special functions' menu
@ -9555,9 +9531,6 @@ static int32_t osdcmd_do(const osdfuncparm_t *parm)
// asksave = 1; // handled in Access(Sprite|Sector|Wall)
}
return OSDCMD_OK;
OUTOFMEM:
message("OUT OF MEMORY!\n");
return OSDCMD_OK;
}
@ -9905,8 +9878,8 @@ int32_t parsetilegroups(scriptfile *script)
if (scriptfile_getstring(script,&name)) break;
if (scriptfile_getbraces(script,&end)) break;
s_TileGroups[tile_groups].pIds = (int32_t *)Bcalloc(MAX_TILE_GROUP_ENTRIES, sizeof(int32_t));
s_TileGroups[tile_groups].szText = Bstrdup(name);
s_TileGroups[tile_groups].pIds = (int32_t *)Xcalloc(MAX_TILE_GROUP_ENTRIES, sizeof(int32_t));
s_TileGroups[tile_groups].szText = Xstrdup(name);
while (script->textptr < end)
{
@ -9980,7 +9953,7 @@ int32_t parsetilegroups(scriptfile *script)
}
}
s_TileGroups[tile_groups].pIds = (int32_t *)Brealloc(s_TileGroups[tile_groups].pIds,
s_TileGroups[tile_groups].pIds = (int32_t *)Xrealloc(s_TileGroups[tile_groups].pIds,
s_TileGroups[tile_groups].nIds*sizeof(int32_t));
tile_groups++;
break;
@ -10133,10 +10106,9 @@ static int32_t loadtilegroups(const char *fn)
tile_groups = 0;
#if 0
// ---------- Init hardcoded tile group consisting of all named tiles
s_TileGroups[0].szText = Bstrdup("All named");
s_TileGroups[0].pIds = (int32_t *)Bmalloc(MAXTILES * sizeof(s_TileGroups[0].pIds[0]));
if (!s_TileGroups[0].pIds)
return -1;
s_TileGroups[0].szText = Xstrdup("All named");
s_TileGroups[0].pIds = (int32_t *)Xmalloc(MAXTILES * sizeof(s_TileGroups[0].pIds[0]));
j = 0;
for (i=0; i<MAXTILES; i++)
if (names[i][0])
@ -10260,8 +10232,7 @@ static int32_t parseconsounds(scriptfile *script)
if (scriptfile_getsymbol(script, &sndnum)) break;
definedname = Bstrdup(script->ltextptr);
if (!definedname) return -1;
definedname = Xstrdup(script->ltextptr);
if (sndnum < 0 || sndnum >= MAXSOUNDS)
{
@ -10294,7 +10265,7 @@ static int32_t parseconsounds(scriptfile *script)
duplicate = 1;
Bfree(g_sounds[sndnum].filename);
}
g_sounds[sndnum].filename = (char *)Bcalloc(slen+1,sizeof(uint8_t));
g_sounds[sndnum].filename = (char *)Xcalloc(slen+1,sizeof(uint8_t));
// Hopefully noone does memcpy(..., g_sounds[].filename, BMAX_PATH)
if (!g_sounds[sndnum].filename)
{
@ -10595,7 +10566,7 @@ int32_t ExtInit(void)
registerosdcommands();
{
char *ptr = Bstrdup(setupfilename), *p = strtok(ptr,".");
char *ptr = Xstrdup(setupfilename), *p = strtok(ptr,".");
if (!Bstrcmp(setupfilename, SETUPFILENAME))
Bsprintf(tempbuf, "m32_settings.cfg");
else Bsprintf(tempbuf,"%s_m32_settings.cfg",p);
@ -11760,10 +11731,8 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
if (!corruptcheck_noalreadyrefd)
{
seen_nextwalls = (uint8_t *)Bcalloc((numwalls+7)>>3,1);
if (!seen_nextwalls) return 5;
lastnextwallsource = (int16_t *)Bmalloc(numwalls*sizeof(lastnextwallsource[0]));
if (!lastnextwallsource) { Bfree(seen_nextwalls); return 5; }
seen_nextwalls = (uint8_t *)Xcalloc((numwalls+7)>>3,1);
lastnextwallsource = (int16_t *)Xmalloc(numwalls*sizeof(lastnextwallsource[0]));
}
for (i=0; i<numsectors; i++)
@ -13125,7 +13094,7 @@ static void M_RegisterFunction(StatusBarMenu *m, const char *name, intptr_t auxd
#if MENU_HAVE_DESCRIPTION
// NOTE: description only handled here (not above).
if (description)
m->description[m->numentries] = Bstrdup(description);
m->description[m->numentries] = Xstrdup(description);
#else
UNREFERENCED_PARAMETER(description);
#endif
@ -13323,10 +13292,7 @@ static void FuncMenu_Process(const StatusBarMenu *m, int32_t col, int32_t row)
const char *statename = statesinfo[stateidx].name;
int32_t snlen = Bstrlen(statename);
char *tmpscript = (char *)Bmalloc(1+5+1+snlen+1);
if (!tmpscript)
break;
char *tmpscript = (char *)Xmalloc(1+5+1+snlen+1);
tmpscript[0] = ' '; // don't save in history
Bmemcpy(&tmpscript[1], "state", 5);

View file

@ -373,14 +373,14 @@ void G_AddGroup(const char *buffer)
{
char buf[BMAX_PATH];
struct strllist *s = (struct strllist *)Bcalloc(1,sizeof(struct strllist));
struct strllist *s = (struct strllist *)Xcalloc(1,sizeof(struct strllist));
Bstrcpy(buf, buffer);
if (Bstrchr(buf,'.') == 0)
Bstrcat(buf,".grp");
s->str = Bstrdup(buf);
s->str = Xstrdup(buf);
if (CommandGrps)
{
@ -394,8 +394,8 @@ void G_AddGroup(const char *buffer)
void G_AddPath(const char *buffer)
{
struct strllist *s = (struct strllist *)Bcalloc(1,sizeof(struct strllist));
s->str = Bstrdup(buffer);
struct strllist *s = (struct strllist *)Xcalloc(1,sizeof(struct strllist));
s->str = Xstrdup(buffer);
if (CommandPaths)
{
@ -416,16 +416,16 @@ void G_AddDef(const char *buffer)
void G_AddDefModule(const char *buffer)
{
g_defModules = (char **) Brealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *));
g_defModules[g_defModulesNum] = Bstrdup(buffer);
g_defModules = (char **) Xrealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *));
g_defModules[g_defModulesNum] = Xstrdup(buffer);
++g_defModulesNum;
}
#ifdef HAVE_CLIPSHAPE_FEATURE
void G_AddClipMap(const char *buffer)
{
g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(buffer);
g_clipMapFiles = (char **) Xrealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(buffer);
++g_clipMapFilesNum;
}
#endif
@ -439,8 +439,8 @@ void G_AddCon(const char *buffer)
void G_AddConModule(const char *buffer)
{
g_scriptModules = (char **) Brealloc (g_scriptModules, (g_scriptModulesNum+1) * sizeof(char *));
g_scriptModules[g_scriptModulesNum] = Bstrdup(buffer);
g_scriptModules = (char **) Xrealloc (g_scriptModules, (g_scriptModulesNum+1) * sizeof(char *));
g_scriptModules[g_scriptModulesNum] = Xstrdup(buffer);
++g_scriptModulesNum;
}
@ -575,7 +575,7 @@ void G_DoAutoload(const char *dirname)
// returns a buffer of size BMAX_PATH
char *dup_filename(const char *fn)
{
char *buf = (char *)Bmalloc(BMAX_PATH);
char *buf = (char *)Xmalloc(BMAX_PATH);
return Bstrncpyz(buf, fn, BMAX_PATH);
}

View file

@ -68,7 +68,7 @@ int32_t CONFIG_FunctionNameToNum(const char *func)
if (i < 0)
{
char *str = Bstrtolower(Bstrdup(func));
char *str = Bstrtolower(Xstrdup(func));
i = hash_find(&h_gamefuncs,str);
Bfree(str);
@ -749,7 +749,7 @@ void CONFIG_WriteBinds(void) // save binds and aliases to <cfgname>_settings.cfg
{
int32_t i;
BFILE *fp;
char *ptr = Bstrdup(setupfilename);
char *ptr = Xstrdup(setupfilename);
char tempbuf[128];
if (!Bstrcmp(setupfilename, SETUPFILENAME))

View file

@ -362,7 +362,7 @@ int32_t G_GetStringNumLines(const char *text, const char *end, const int32_t ite
// This function requires you to Bfree() the returned char*.
char* G_GetSubString(const char *text, const char *end, const int32_t iter, const int32_t length)
{
char *line = (char*)Bmalloc((length+1) * sizeof(char));
char *line = (char*)Xmalloc((length+1) * sizeof(char));
int32_t counter = 0;
while (counter < length && text != end)
@ -4360,7 +4360,7 @@ static void G_ReadGLFrame(void)
{
// Save OpenGL screenshot with Duke3D palette
// NOTE: maybe need to move this to the engine...
palette_t *const frame = (palette_t *const) Bcalloc(xdim * ydim, sizeof(palette_t));
palette_t *const frame = (palette_t *const)Xcalloc(xdim * ydim, sizeof(palette_t));
char *const pic = (char *) waloff[TILE_SAVESHOT];
int32_t x, y;
@ -9223,10 +9223,7 @@ static char *S_OggifyFilename(char *outputname, char *newname, const char *orign
if (!origname)
return outputname;
outputname = (char *)Brealloc(outputname, Bstrlen(newname) + Bstrlen(origname) + 1);
if (!outputname)
return NULL;
outputname = (char *)Xrealloc(outputname, Bstrlen(newname) + Bstrlen(origname) + 1);
Bstrcpy(outputname, *newname ? newname : origname);
@ -9485,7 +9482,7 @@ static int32_t parsedefinitions_game(scriptfile *script, int32_t preload)
}
if (!preload)
anim_hi_sounds[animnum] = (uint16_t *)Bcalloc(allocsz, 2*sizeof(anim_hi_sounds[0]));
anim_hi_sounds[animnum] = (uint16_t *)Xcalloc(allocsz, 2*sizeof(anim_hi_sounds[0]));
while (script->textptr < animsoundsend)
{
int32_t framenum, soundnum;
@ -9509,6 +9506,7 @@ static int32_t parsedefinitions_game(scriptfile *script, int32_t preload)
bad=1;
// TODO: look carefully at whether this can be removed.
if (anim_hi_sounds[animnum]==NULL) // Bcalloc check
break;
@ -9543,9 +9541,8 @@ static int32_t parsedefinitions_game(scriptfile *script, int32_t preload)
void *newptr;
allocsz *= 2;
newptr = Brealloc(anim_hi_sounds[animnum], allocsz*2*sizeof(anim_hi_sounds[0]));
newptr = Xrealloc(anim_hi_sounds[animnum], allocsz*2*sizeof(anim_hi_sounds[0]));
if (!newptr) break;
anim_hi_sounds[animnum] = (uint16_t *)newptr;
}
@ -9708,8 +9705,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
#ifdef LUNATIC
g_argv = argv;
g_elModules = (const char **)Bcalloc(argc+1, sizeof(char *));
Bassert(g_elModules);
g_elModules = (const char **)Xcalloc(argc+1, sizeof(char *));
#endif
ud.fta_on = 1;
ud.god = 0;
@ -9737,8 +9733,8 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
char clipshape[16] = "_clipshape0.map";
clipshape[10] = j;
g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(clipshape);
g_clipMapFiles = (char **)Xrealloc(g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(clipshape);
++g_clipMapFilesNum;
}
#endif
@ -10687,11 +10683,8 @@ static void G_CompileScripts(void)
char *newlabel;
int32_t *newlabelcode;
newlabel = (char *)Bmalloc(g_numLabels<<6);
newlabelcode = (int32_t *)Bmalloc(g_numLabels*sizeof(int32_t));
if (!newlabel || !newlabelcode)
G_GameExit("Error: out of memory retaining labels\n");
newlabel = (char *)Xmalloc(g_numLabels<<6);
newlabelcode = (int32_t *)Xmalloc(g_numLabels*sizeof(int32_t));
Bmemcpy(newlabel, label, g_numLabels*64);
Bmemcpy(newlabelcode, labelcode, g_numLabels*sizeof(int32_t));
@ -10775,9 +10768,7 @@ LUNATIC_EXTERN void El_SetCON(const char *conluacode)
{
int32_t slen = Bstrlen(conluacode);
g_elCON = (char *)Bmalloc(slen);
if (g_elCON == NULL)
G_GameExit("OUT OF MEMORY in El_SetCON!");
g_elCON = (char *)Xmalloc(slen);
g_elCONSize = slen;
Bmemcpy(g_elCON, conluacode, slen);
@ -11149,12 +11140,10 @@ DukePlayer_t *g_player_ps[MAXPLAYERS];
void G_MaybeAllocPlayer(int32_t pnum)
{
if (g_player[pnum].ps == NULL)
g_player[pnum].ps = (DukePlayer_t *)Bcalloc(1, sizeof(DukePlayer_t));
g_player[pnum].ps = (DukePlayer_t *)Xcalloc(1, sizeof(DukePlayer_t));
if (g_player[pnum].sync == NULL)
g_player[pnum].sync = (input_t *)Bcalloc(1, sizeof(input_t));
g_player[pnum].sync = (input_t *)Xcalloc(1, sizeof(input_t));
if (g_player[pnum].ps == NULL || g_player[pnum].sync == NULL)
G_GameExit("OUT OF MEMORY");
#ifdef LUNATIC
g_player_ps[pnum] = g_player[pnum].ps;
g_player[pnum].ps->wa.idx = pnum;
@ -11383,7 +11372,7 @@ int32_t app_main(int32_t argc, const char **argv)
hash_init(&h_gamefuncs);
for (i=NUMGAMEFUNCTIONS-1; i>=0; i--)
{
char *str = Bstrtolower(Bstrdup(gamefunctions[i]));
char *str = Bstrtolower(Xstrdup(gamefunctions[i]));
hash_add(&h_gamefuncs,gamefunctions[i],i,0);
hash_add(&h_gamefuncs,str,i,0);
Bfree(str);
@ -11785,7 +11774,7 @@ int32_t app_main(int32_t argc, const char **argv)
}
{
char *ptr = Bstrdup(setupfilename), *p = strtok(ptr,".");
char *ptr = Xstrdup(setupfilename), *p = strtok(ptr,".");
if (!Bstrcmp(setupfilename, SETUPFILENAME))
Bsprintf(tempbuf, "settings.cfg");
else Bsprintf(tempbuf,"%s_settings.cfg",p);

View file

@ -214,7 +214,8 @@ static const char *C_GetLabelType(int32_t type)
if (x[0]) Bstrcat(x, " or ");
Bstrcat(x, LabelTypeText[i]);
}
return Bstrdup(x);
return Xstrdup(x);
}
@ -1259,7 +1260,7 @@ static int32_t C_SetScriptSize(int32_t newsize)
char *scriptptrs;
char *newbitptr;
scriptptrs = (char *)Bcalloc(1, g_scriptSize * sizeof(uint8_t));
scriptptrs = (char *)Xcalloc(1, g_scriptSize * sizeof(uint8_t));
for (i=g_scriptSize-1; i>=0; i--)
{
@ -1283,17 +1284,8 @@ static int32_t C_SetScriptSize(int32_t newsize)
initprintf("Resizing code buffer to %d*%d bytes\n",newsize, (int32_t)sizeof(intptr_t));
newscript = (intptr_t *)Brealloc(script, newsize * sizeof(intptr_t));
newbitptr = (char *)Bcalloc(1,(((newsize+7)>>3)+1) * sizeof(uint8_t));
if (newscript == NULL || newbitptr == NULL)
{
C_ReportError(-1);
initprintf("%s:%d: out of memory: Aborted (%ud)\n",g_szScriptFileName,g_lineNumber,(unsigned)(g_scriptPtr-script));
initprintf("%s", tempbuf);
g_numCompilerErrors++;
return 1;
}
newscript = (intptr_t *)Xrealloc(script, newsize * sizeof(intptr_t));
newbitptr = (char *)Xcalloc(1,(((newsize+7)>>3)+1) * sizeof(uint8_t));
if (newsize >= osize)
{
@ -2053,15 +2045,7 @@ static void C_Include(const char *confile)
j = kfilelength(fp);
mptr = (char *)Bmalloc(j+1);
if (!mptr)
{
kclose(fp);
g_numCompilerErrors++;
initprintf("%s:%d: error: could not allocate %d bytes to include `%s'.\n",
g_szScriptFileName,g_lineNumber,j,confile);
return;
}
mptr = (char *)Xmalloc(j+1);
initprintf("Including: %s (%d bytes)\n",confile, j);
kread(fp, mptr, j);
@ -2253,7 +2237,7 @@ void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn,
// TODO: truncate to 32 chars?
Bfree(map->name);
map->name = Bstrdup(levelname);
map->name = Xstrdup(levelname);
map->partime = REALGAMETICSPERSEC * partime;
map->designertime = REALGAMETICSPERSEC * designertime;
@ -2363,13 +2347,7 @@ int32_t C_AllocQuote(int32_t qnum)
if (ScriptQuotes[qnum] == NULL)
{
ScriptQuotes[qnum] = (char *)Bcalloc(MAXQUOTELEN,sizeof(uint8_t));
if (ScriptQuotes[qnum] == NULL)
{
Bsprintf(tempbuf, "Failed allocating %d byte quote text buffer.", MAXQUOTELEN);
G_GameExit(tempbuf);
}
ScriptQuotes[qnum] = (char *)Xcalloc(MAXQUOTELEN,sizeof(uint8_t));
return 1;
}
@ -2997,9 +2975,9 @@ static int32_t C_ParseCommand(int32_t loop)
tempbuf[j+1] = '\0';
if (MapInfo[(k*MAXLEVELS)+i].musicfn == NULL)
MapInfo[(k*MAXLEVELS)+i].musicfn = (char *)Bcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
MapInfo[(k*MAXLEVELS)+i].musicfn = (char *)Xcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
else if ((Bstrlen(tempbuf)+1) > sizeof(MapInfo[(k*MAXLEVELS)+i].musicfn))
MapInfo[(k*MAXLEVELS)+i].musicfn = (char *)Brealloc(MapInfo[(k*MAXLEVELS)+i].musicfn,(Bstrlen(tempbuf)+1));
MapInfo[(k*MAXLEVELS)+i].musicfn = (char *)Xrealloc(MapInfo[(k*MAXLEVELS)+i].musicfn,(Bstrlen(tempbuf)+1));
Bstrcpy(MapInfo[(k*MAXLEVELS)+i].musicfn,tempbuf);
@ -5491,7 +5469,7 @@ repeatcase:
keydefaults[j*3][i] = '\0';
hash_add(&h_gamefuncs,gamefunctions[j],j,0);
{
char *str = Bstrtolower(Bstrdup(gamefunctions[j]));
char *str = Bstrtolower(Xstrdup(gamefunctions[j]));
hash_add(&h_gamefuncs,str,j,0);
Bfree(str);
}
@ -5563,7 +5541,7 @@ repeatcase:
}
}
gamename[i] = '\0';
g_gameNamePtr = Bstrdup(gamename);
g_gameNamePtr = Xstrdup(gamename);
Bsprintf(tempbuf,"%s - " APPNAME,g_gameNamePtr);
wm_setapptitle(tempbuf);
}
@ -5688,9 +5666,9 @@ repeatcase:
Bcorrectfilename(tempbuf,0);
if (MapInfo[j *MAXLEVELS+k].filename == NULL)
MapInfo[j *MAXLEVELS+k].filename = (char *)Bcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
MapInfo[j *MAXLEVELS+k].filename = (char *)Xcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
else if ((Bstrlen(tempbuf)+1) > sizeof(MapInfo[j*MAXLEVELS+k].filename))
MapInfo[j *MAXLEVELS+k].filename = (char *)Brealloc(MapInfo[j*MAXLEVELS+k].filename,(Bstrlen(tempbuf)+1));
MapInfo[j *MAXLEVELS+k].filename = (char *)Xrealloc(MapInfo[j*MAXLEVELS+k].filename,(Bstrlen(tempbuf)+1));
Bstrcpy(MapInfo[j*MAXLEVELS+k].filename,tempbuf);
@ -5734,9 +5712,9 @@ repeatcase:
tempbuf[i] = '\0';
if (MapInfo[j*MAXLEVELS+k].name == NULL)
MapInfo[j*MAXLEVELS+k].name = (char *)Bcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
MapInfo[j*MAXLEVELS+k].name = (char *)Xcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
else if ((Bstrlen(tempbuf)+1) > sizeof(MapInfo[j*MAXLEVELS+k].name))
MapInfo[j *MAXLEVELS+k].name = (char *)Brealloc(MapInfo[j*MAXLEVELS+k].name,(Bstrlen(tempbuf)+1));
MapInfo[j *MAXLEVELS+k].name = (char *)Xrealloc(MapInfo[j*MAXLEVELS+k].name,(Bstrlen(tempbuf)+1));
/* initprintf("level name string len: %d\n",Bstrlen(tempbuf)); */
@ -5776,12 +5754,7 @@ repeatcase:
if (tw == CON_REDEFINEQUOTE)
{
if (ScriptQuoteRedefinitions[g_numQuoteRedefinitions] == NULL)
ScriptQuoteRedefinitions[g_numQuoteRedefinitions] = (char *)Bcalloc(MAXQUOTELEN,sizeof(uint8_t));
if (ScriptQuoteRedefinitions[g_numQuoteRedefinitions] == NULL)
{
Bsprintf(tempbuf,"Failed allocating %" PRIdPTR " byte quote text buffer.",sizeof(uint8_t) * MAXQUOTELEN);
G_GameExit(tempbuf);
}
ScriptQuoteRedefinitions[g_numQuoteRedefinitions] = (char *)Xcalloc(MAXQUOTELEN,sizeof(uint8_t));
}
while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0)
@ -5883,12 +5856,7 @@ repeatcase:
C_SkipComments();
if (g_sounds[k].filename == NULL)
g_sounds[k].filename = (char *)Bcalloc(BMAX_PATH,sizeof(uint8_t));
if (!g_sounds[k].filename)
{
Bsprintf(tempbuf,"Failed allocating %" PRIdPTR " byte buffer.",sizeof(uint8_t) * BMAX_PATH);
G_GameExit(tempbuf);
}
g_sounds[k].filename = (char *)Xcalloc(BMAX_PATH,sizeof(uint8_t));
if (*textptr == '\"')
{
@ -6364,13 +6332,7 @@ void C_Compile(const char *filenam)
startcompiletime = getticks();
mptr = (char *)Bmalloc(fs+1);
if (!mptr)
{
Bsprintf(tempbuf,"Failed allocating %d byte CON text buffer.", fs+1);
G_GameExit(tempbuf);
}
mptr = (char *)Xmalloc(fs+1);
mptr[fs] = 0;
textptr = (char *) mptr;
@ -6380,8 +6342,8 @@ void C_Compile(const char *filenam)
if (script != NULL)
Bfree(script);
script = (intptr_t *)Bcalloc(1,g_scriptSize * sizeof(intptr_t));
bitptr = (char *)Bcalloc(1,(((g_scriptSize+7)>>3)+1) * sizeof(uint8_t));
script = (intptr_t *)Xcalloc(1,g_scriptSize * sizeof(intptr_t));
bitptr = (char *)Xcalloc(1,(((g_scriptSize+7)>>3)+1) * sizeof(uint8_t));
// initprintf("script: %d, bitptr: %d\n",script,bitptr);
g_numLabels = g_numDefaultLabels = 0;

View file

@ -4430,7 +4430,7 @@ finish_qsprintf:
// NOTE: this is broken on 64-bit, e.g. for LNGA2.
/*OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n",
aGameArrays[j].szLabel, aGameArrays[j].size, asize / GAR_ELTSZ);*/
aGameArrays[j].plValues = (intptr_t *)Brealloc(aGameArrays[j].plValues, asize);
aGameArrays[j].plValues = (intptr_t *)Xrealloc(aGameArrays[j].plValues, asize);
aGameArrays[j].size = asize / GAR_ELTSZ;
kread(fil, aGameArrays[j].plValues, asize);
}
@ -4482,7 +4482,7 @@ finish_qsprintf:
if (asize > 0)
{
/*OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n", aGameArrays[j].szLabel, aGameArrays[j].size, asize);*/
aGameArrays[j].plValues = (intptr_t *)Brealloc(aGameArrays[j].plValues, GAR_ELTSZ * asize);
aGameArrays[j].plValues = (intptr_t *)Xrealloc(aGameArrays[j].plValues, GAR_ELTSZ * asize);
aGameArrays[j].size = asize;
}
continue;
@ -5507,7 +5507,7 @@ void G_SaveMapState(void)
mapstate_t *save;
if (mapinfo->savedstate == NULL)
mapinfo->savedstate = (mapstate_t *)Bcalloc(1,sizeof(mapstate_t));
mapinfo->savedstate = (mapstate_t *)Xcalloc(1,sizeof(mapstate_t));
save = mapinfo->savedstate;
if (save != NULL)
@ -5588,13 +5588,13 @@ void G_SaveMapState(void)
if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)
{
if (!save->vars[i])
save->vars[i] = (intptr_t *)Bcalloc(MAXPLAYERS,sizeof(intptr_t));
save->vars[i] = (intptr_t *)Xcalloc(MAXPLAYERS,sizeof(intptr_t));
Bmemcpy(&save->vars[i][0],&aGameVars[i].val.plValues[0],sizeof(intptr_t) * MAXPLAYERS);
}
else if (aGameVars[i].dwFlags & GAMEVAR_PERACTOR)
{
if (!save->vars[i])
save->vars[i] = (intptr_t *)Bcalloc(MAXSPRITES,sizeof(intptr_t));
save->vars[i] = (intptr_t *)Xcalloc(MAXSPRITES,sizeof(intptr_t));
Bmemcpy(&save->vars[i][0],&aGameVars[i].val.plValues[0],sizeof(intptr_t) * MAXSPRITES);
}
else save->vars[i] = (intptr_t *)aGameVars[i].val.lValue;
@ -5610,9 +5610,7 @@ void G_SaveMapState(void)
}
else
{
char *savecode = Bstrdup(svcode);
if (savecode == NULL)
G_GameExit("OUT OF MEMORY in G_SaveMapState!");
char *savecode = Xstrdup(svcode);
Bfree(save->savecode);
save->savecode = savecode;
}

View file

@ -117,18 +117,18 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
for (i=0; i<g_gameVarCount; i++)
{
if (kdfread(&(aGameVars[i]),sizeof(gamevar_t),1,fil) != 1) goto corrupt;
aGameVars[i].szLabel = (char *)Bcalloc(MAXVARLABEL,sizeof(uint8_t));
aGameVars[i].szLabel = (char *)Xcalloc(MAXVARLABEL,sizeof(uint8_t));
if (kdfread(aGameVars[i].szLabel,sizeof(uint8_t) * MAXVARLABEL, 1, fil) != 1) goto corrupt;
hash_add(&h_gamevars, aGameVars[i].szLabel,i, 1);
if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)
{
aGameVars[i].val.plValues = (intptr_t*)Bcalloc(MAXPLAYERS,sizeof(intptr_t));
aGameVars[i].val.plValues = (intptr_t*)Xcalloc(MAXPLAYERS,sizeof(intptr_t));
if (kdfread(aGameVars[i].val.plValues,sizeof(intptr_t) * MAXPLAYERS, 1, fil) != 1) goto corrupt;
}
else if (aGameVars[i].dwFlags & GAMEVAR_PERACTOR)
{
aGameVars[i].val.plValues = (intptr_t*)Bcalloc(MAXSPRITES,sizeof(intptr_t));
aGameVars[i].val.plValues = (intptr_t*)Xcalloc(MAXSPRITES,sizeof(intptr_t));
if (kdfread(&aGameVars[i].val.plValues[0],sizeof(intptr_t), MAXSPRITES, fil) != MAXSPRITES) goto corrupt;
}
}
@ -150,11 +150,11 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
// read for .size and .dwFlags (the rest are pointers):
if (kdfread(&aGameArrays[i],sizeof(gamearray_t),1,fil) != 1) goto corrupt;
aGameArrays[i].szLabel = (char *)Bcalloc(MAXARRAYLABEL,sizeof(uint8_t));
aGameArrays[i].szLabel = (char *)Xcalloc(MAXARRAYLABEL,sizeof(uint8_t));
if (kdfread(aGameArrays[i].szLabel,sizeof(uint8_t) * MAXARRAYLABEL, 1, fil) != 1) goto corrupt;
hash_add(&h_arrays, aGameArrays[i].szLabel, i, 1);
aGameArrays[i].plValues = (intptr_t *)Bcalloc(aGameArrays[i].size, GAR_ELTSZ);
aGameArrays[i].plValues = (intptr_t *)Xcalloc(aGameArrays[i].size, GAR_ELTSZ);
if (kdfread(aGameArrays[i].plValues, GAR_ELTSZ * aGameArrays[i].size, 1, fil) < 1) goto corrupt;
}
@ -173,7 +173,7 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
if (savedstate[i])
{
if (MapInfo[i].savedstate == NULL)
MapInfo[i].savedstate = (mapstate_t *)Bcalloc(1,sizeof(mapstate_t));
MapInfo[i].savedstate = (mapstate_t *)Xcalloc(1,sizeof(mapstate_t));
if (kdfread(MapInfo[i].savedstate,sizeof(mapstate_t),1,fil) != sizeof(mapstate_t)) goto corrupt;
for (j=0; j<g_gameVarCount; j++)
{
@ -181,13 +181,13 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
if (aGameVars[j].dwFlags & GAMEVAR_PERPLAYER)
{
// if (!MapInfo[i].savedstate->vars[j])
MapInfo[i].savedstate->vars[j] = (intptr_t *)Bcalloc(MAXPLAYERS,sizeof(intptr_t));
MapInfo[i].savedstate->vars[j] = (intptr_t *)Xcalloc(MAXPLAYERS,sizeof(intptr_t));
if (kdfread(&MapInfo[i].savedstate->vars[j][0],sizeof(intptr_t) * MAXPLAYERS, 1, fil) != 1) goto corrupt;
}
else if (aGameVars[j].dwFlags & GAMEVAR_PERACTOR)
{
// if (!MapInfo[i].savedstate->vars[j])
MapInfo[i].savedstate->vars[j] = (intptr_t *)Bcalloc(MAXSPRITES,sizeof(intptr_t));
MapInfo[i].savedstate->vars[j] = (intptr_t *)Xcalloc(MAXSPRITES,sizeof(intptr_t));
if (kdfread(&MapInfo[i].savedstate->vars[j][0],sizeof(intptr_t), MAXSPRITES, fil) != MAXSPRITES) goto corrupt;
}
}
@ -424,12 +424,12 @@ int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32
i = g_gameArrayCount;
if (aGameArrays[i].szLabel == NULL)
aGameArrays[i].szLabel=(char *)Bcalloc(MAXVARLABEL,sizeof(uint8_t));
aGameArrays[i].szLabel=(char *)Xcalloc(MAXVARLABEL,sizeof(uint8_t));
if (aGameArrays[i].szLabel != pszLabel)
Bstrcpy(aGameArrays[i].szLabel,pszLabel);
if (!(dwFlags & GAMEARRAY_TYPE_MASK))
aGameArrays[i].plValues=(intptr_t *)Bcalloc(asize,GAR_ELTSZ);
aGameArrays[i].plValues=(intptr_t *)Xcalloc(asize,GAR_ELTSZ);
else
aGameArrays[i].plValues=(intptr_t *)arrayptr;
@ -493,7 +493,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
{
// Allocate and set its label
if (aGameVars[i].szLabel == NULL)
aGameVars[i].szLabel = (char *)Bcalloc(MAXVARLABEL,sizeof(uint8_t));
aGameVars[i].szLabel = (char *)Xcalloc(MAXVARLABEL,sizeof(uint8_t));
if (aGameVars[i].szLabel != pszLabel)
Bstrcpy(aGameVars[i].szLabel,pszLabel);
@ -522,14 +522,14 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)
{
if (!aGameVars[i].val.plValues)
aGameVars[i].val.plValues = (intptr_t *)Bcalloc(MAXPLAYERS,sizeof(intptr_t));
aGameVars[i].val.plValues = (intptr_t *)Xcalloc(MAXPLAYERS,sizeof(intptr_t));
for (j=MAXPLAYERS-1; j>=0; j--)
aGameVars[i].val.plValues[j]=lValue;
}
else if (aGameVars[i].dwFlags & GAMEVAR_PERACTOR)
{
if (!aGameVars[i].val.plValues)
aGameVars[i].val.plValues = (intptr_t *)Bcalloc(MAXSPRITES,sizeof(intptr_t));
aGameVars[i].val.plValues = (intptr_t *)Xcalloc(MAXSPRITES,sizeof(intptr_t));
for (j=MAXSPRITES-1; j>=0; j--)
aGameVars[i].val.plValues[j]=lValue;
}

View file

@ -140,12 +140,12 @@ static void LoadList(const char * filename)
break;
}
fg = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
fg = (struct grpfile *)Xcalloc(1, sizeof(struct grpfile));
fg->next = listgrps;
listgrps = fg;
if (gname)
fg->name = Bstrdup(gname);
fg->name = Xstrdup(gname);
fg->size = gsize;
fg->crcval = gcrcval;
@ -179,9 +179,9 @@ static void LoadGameList(void)
for (i = 0; i<NUMGRPFILES; i++)
{
fg = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
fg = (struct grpfile *)Xcalloc(1, sizeof(struct grpfile));
fg->name = Bstrdup(internalgrpfiles[i].name);
fg->name = Xstrdup(internalgrpfiles[i].name);
fg->crcval = internalgrpfiles[i].crcval;
fg->size = internalgrpfiles[i].size;
fg->game = internalgrpfiles[i].game;
@ -256,7 +256,7 @@ static int32_t LoadGroupsCache(void)
if (scriptfile_getnumber(script, &fmtime)) break; // modification time
if (scriptfile_getnumber(script, &fcrcval)) break; // crc checksum
fg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
fg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache));
fg->next = grpcache;
grpcache = fg;
@ -337,13 +337,7 @@ int32_t ScanGroups(void)
char *fn;
struct Bstat st;
#define BUFFER_SIZE (1024 * 1024 * 8)
uint8_t *buf = (uint8_t *)Bmalloc(BUFFER_SIZE);
if (!buf)
{
initprintf("Error allocating %d byte buffer to scan GRPs!\n", BUFFER_SIZE);
return 0;
}
uint8_t *buf = (uint8_t *)Xmalloc(BUFFER_SIZE);
initprintf("Searching for game data...\n");
@ -370,14 +364,14 @@ int32_t ScanGroups(void)
Bfree(fn);
if (fg->size == st.st_size && fg->mtime == st.st_mtime)
{
grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
grp->name = Bstrdup(sidx->name);
grp = (struct grpfile *)Xcalloc(1, sizeof(struct grpfile));
grp->name = Xstrdup(sidx->name);
grp->crcval = fg->crcval;
grp->size = fg->size;
grp->next = foundgrps;
foundgrps = grp;
fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache));
strcpy(fgg->name, fg->name);
fgg->size = fg->size;
fgg->mtime = fg->mtime;
@ -408,14 +402,14 @@ int32_t ScanGroups(void)
close(fh);
initprintf(" Done\n");
grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
grp->name = Bstrdup(sidx->name);
grp = (struct grpfile *)Xcalloc(1, sizeof(struct grpfile));
grp->name = Xstrdup(sidx->name);
grp->crcval = crcval;
grp->size = st.st_size;
grp->next = foundgrps;
foundgrps = grp;
fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache));
Bstrncpy(fgg->name, sidx->name, BMAX_PATH);
fgg->size = st.st_size;
fgg->mtime = st.st_mtime;

View file

@ -263,7 +263,7 @@ int32_t ANIM_LoadAnim(const uint8_t *buffer, int32_t length)
if (length < 0)
return -1;
anim = (anim_t *)Brealloc(anim, sizeof(anim_t));
anim = (anim_t *)Xrealloc(anim, sizeof(anim_t));
anim->curlpnum = 0xffff;
anim->currentframe = -1;

View file

@ -70,8 +70,8 @@ int32_t SafeOpen(const char *filename, int32_t mode, int32_t sharemode)
if (h < MaxFiles)
{
if (FileNames[h]) Bfree(FileNames[h]);
FileNames[h] = (char*)Bmalloc(strlen(filename)+1);
if (FileNames[h]) strcpy(FileNames[h], filename);
FileNames[h] = (char*)Xmalloc(strlen(filename)+1);
strcpy(FileNames[h], filename);
}
return h;

View file

@ -56,8 +56,7 @@ int32_t SCRIPT_New(void)
{
if (!SC(i))
{
SC(i) = (script_t *)Bmalloc(sizeof(script_t));
if (!SC(i)) return -1;
SC(i) = (script_t *)Xmalloc(sizeof(script_t));
memset(SC(i), 0, sizeof(script_t));
return i;
}
@ -122,7 +121,7 @@ void SCRIPT_FreeSection(ScriptSectionType * section)
#define AllocSection(s) \
{ \
(s) = (ScriptSectionType *)Bmalloc(sizeof(ScriptSectionType)); \
(s) = (ScriptSectionType *)Xmalloc(sizeof(ScriptSectionType)); \
(s)->name = NULL; \
(s)->entries = NULL; \
(s)->lastline = NULL; \
@ -131,7 +130,7 @@ void SCRIPT_FreeSection(ScriptSectionType * section)
}
#define AllocEntry(e) \
{ \
(e) = (ScriptEntryType *)Bmalloc(sizeof(ScriptEntryType)); \
(e) = (ScriptEntryType *)Xmalloc(sizeof(ScriptEntryType)); \
(e)->name = NULL; \
(e)->value = NULL; \
(e)->nextentry = (e); \
@ -451,7 +450,7 @@ int32_t SCRIPT_Load(char * filename)
h = SafeOpenRead(filename, filetype_binary);
l = SafeFileLength(h)+1;
b = (char *)Bmalloc(l);
b = (char *)Xmalloc(l);
SafeRead(h,b,l-1);
b[l-1] = '\n'; // JBF 20040111: evil nasty hack to trick my evil nasty parser
SafeClose(h);
@ -609,7 +608,7 @@ static char * SCRIPT_ParseString(char ** dest, char * p)
}
// allocate
*dest = (char*)Bcalloc(c+1,sizeof(char));
*dest = (char*)Xcalloc(c+1,sizeof(char));
c = 0;
}
@ -801,7 +800,7 @@ void SCRIPT_PutString
if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
else if (*q >= ' ') len++;
}
p = raw = (char *)Bmalloc(len);
p = raw = (char *)Xmalloc(len);
*(p++) = '"';
for (q=string; *q; q++)
{
@ -842,7 +841,7 @@ void SCRIPT_PutDoubleString
if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
else if (*q >= ' ') len++;
}
p = raw = (char *)Bmalloc(len);
p = raw = (char *)Xmalloc(len);
*(p++) = '"';
for (q=string1; *q; q++)
{

View file

@ -120,7 +120,7 @@ void El_PrintTimes(void)
const int32_t baselen = Bstrlen(basefn);
const int32_t addnlen = Bstrlen(".actors.csv"); // MUST equal that of ".events.csv"
char *fullfn = (char *)Bmalloc(baselen + addnlen + 1);
char *fullfn = (char *)Xmalloc(baselen + addnlen + 1);
BFILE *outf;
if (fullfn == NULL)
@ -269,20 +269,16 @@ LUNATIC_EXTERN void El_OnError(const char *str)
// Otherwise, allocate storage for the potentially clipped error string...
if (nl)
{
errstr = (char *)Bmalloc(nl-str+1);
if (errstr)
{
errstr = (char *)Xmalloc(nl-str+1);
Bmemcpy(errstr, str, nl-str);
errstr[nl-str] = 0;
}
}
else
{
errstr = Bstrdup(str);
errstr = Xstrdup(str);
}
// ...and save it:
if (errstr)
el_errorMsgs[el_numErrors++] = errstr;
}
}

View file

@ -128,7 +128,8 @@ static const char *C_GetLabelType(int32_t type)
if (x[0]) Bstrcat(x, " or ");
Bstrcat(x, LabelTypeText[i]);
}
return strdup(x);
return Xstrdup(x);
}
#define NUMKEYWORDS (int32_t)ARRAY_SIZE(keyw)
@ -624,16 +625,7 @@ static int32_t C_SetScriptSize(int32_t size)
g_scriptSize = size;
initprintf("Resizing code buffer to %d*%d bytes\n", g_scriptSize, (int32_t)sizeof(instype));
newscript = (instype *)Brealloc(script, g_scriptSize * sizeof(instype));
if (newscript == NULL)
{
C_ReportError(-1);
initprintf("%s:%d: out of memory: Aborted (%ud)\n", g_szScriptFileName, g_lineNumber, (unsigned)(g_scriptPtr-script));
g_numCompilerErrors++;
// initprintf(tempbuf);
return 1;
}
newscript = (instype *)Xrealloc(script, g_scriptSize * sizeof(instype));
if (size >= osize)
Bmemset(&newscript[osize], 0, (size-osize) * sizeof(instype));
@ -784,16 +776,10 @@ static int32_t C_CopyLabel(void)
{
if (g_numLabels >= label_allocsize)
{
label = (char *)Brealloc(label, 2*label_allocsize*MAXLABELLEN*sizeof(char));
labelval = (int32_t *)Brealloc(labelval, 2*label_allocsize*sizeof(labelval[0]));
labeltype = (uint8_t *)Brealloc(labeltype, 2*label_allocsize*sizeof(labeltype[0]));
label = (char *)Xrealloc(label, 2*label_allocsize*MAXLABELLEN*sizeof(char));
labelval = (int32_t *)Xrealloc(labelval, 2*label_allocsize*sizeof(labelval[0]));
labeltype = (uint8_t *)Xrealloc(labeltype, 2*label_allocsize*sizeof(labeltype[0]));
if (label==NULL || labelval==NULL || labeltype==NULL)
{
label_allocsize = 0;
initprintf("Out of memory!");
return 1;
}
label_allocsize *= 2;
}
@ -1022,13 +1008,7 @@ static void C_GetNextVarType(int32_t type)
if (i>=constants_allocsize)
{
constants_allocsize *= 2;
constants = (int32_t *)Brealloc(constants, constants_allocsize * sizeof(constants[0]));
if (!constants)
{
initprintf("C_GetNextVarType(): ERROR: out of memory!\n");
g_numCompilerErrors++;
return;
}
constants = (int32_t *)Xrealloc(constants, constants_allocsize * sizeof(constants[0]));
}
constants[i] = num;
@ -1740,15 +1720,7 @@ static int32_t C_ParseCommand(void)
j = kfilelength(fp);
mptr = (char *)Bmalloc(j+1);
if (!mptr)
{
kclose(fp);
g_numCompilerErrors++;
initprintf("%s:%d: error: could not allocate %d bytes to include `%s'.\n",
g_szScriptFileName,g_lineNumber,j,tempbuf);
return 1;
}
mptr = (char *)Xmalloc(j+1);
initprintf(" Including: %s (%d bytes)\n", tempbuf, j);
kread(fp, mptr, j);
@ -1823,13 +1795,7 @@ static int32_t C_ParseCommand(void)
if (g_stateCount >= statesinfo_allocsize)
{
statesinfo_allocsize *= 2;
statesinfo = (statesinfo_t *)Brealloc(statesinfo, statesinfo_allocsize * sizeof(statesinfo[0]));
if (!statesinfo)
{
initprintf("C_ParseCommand(): ERROR: out of memory!\n");
g_numCompilerErrors++;
return 1;
}
statesinfo = (statesinfo_t *)Xrealloc(statesinfo, statesinfo_allocsize * sizeof(statesinfo[0]));
}
Bstrcpy(statesinfo[j].name, tlabel);
@ -1849,7 +1815,7 @@ static int32_t C_ParseCommand(void)
if (C_GetNextVarOrString() == 1) // inline string
{
cs.curStateMenuName = Bstrdup((const char *)(oscriptptr+1));
cs.curStateMenuName = Xstrdup((const char *)(oscriptptr+1));
g_scriptPtr = oscriptptr;
}
else
@ -3217,14 +3183,7 @@ repeatcase:
}
if (ScriptQuotes[k] == NULL)
ScriptQuotes[k] = (char *)Bcalloc(MAXQUOTELEN, sizeof(uint8_t));
if (!ScriptQuotes[k])
{
Bsprintf(tempbuf,"Failed allocating %d byte quote text buffer.", MAXQUOTELEN);
g_numCompilerErrors++;
return 1;
}
ScriptQuotes[k] = (char *)Xcalloc(MAXQUOTELEN, sizeof(uint8_t));
if (tw == CON_DEFINEQUOTE)
g_scriptPtr--;
@ -3235,13 +3194,7 @@ repeatcase:
if (tw == CON_REDEFINEQUOTE)
{
if (ScriptQuoteRedefinitions[g_numQuoteRedefinitions] == NULL)
ScriptQuoteRedefinitions[g_numQuoteRedefinitions] = (char *)Bcalloc(MAXQUOTELEN, sizeof(uint8_t));
if (!ScriptQuoteRedefinitions[g_numQuoteRedefinitions])
{
Bsprintf(tempbuf,"Failed allocating %d byte quote text buffer.", MAXQUOTELEN);
g_numCompilerErrors++;
return 1;
}
ScriptQuoteRedefinitions[g_numQuoteRedefinitions] = (char *)Xcalloc(MAXQUOTELEN, sizeof(uint8_t));
}
i = 0;
@ -3693,13 +3646,13 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
if (firstime)
{
label = (char *)Bmalloc(label_allocsize * MAXLABELLEN * sizeof(char));
labelval = (int32_t *)Bmalloc(label_allocsize * sizeof(int32_t));
labeltype = (uint8_t *)Bmalloc(label_allocsize * sizeof(uint8_t));
label = (char *)Xmalloc(label_allocsize * MAXLABELLEN * sizeof(char));
labelval = (int32_t *)Xmalloc(label_allocsize * sizeof(int32_t));
labeltype = (uint8_t *)Xmalloc(label_allocsize * sizeof(uint8_t));
constants = (int32_t *)Bmalloc(constants_allocsize * sizeof(int32_t));
constants = (int32_t *)Xmalloc(constants_allocsize * sizeof(int32_t));
statesinfo = (statesinfo_t *)Bmalloc(statesinfo_allocsize * sizeof(statesinfo_t));
statesinfo = (statesinfo_t *)Xmalloc(statesinfo_allocsize * sizeof(statesinfo_t));
for (i=0; i<MAXEVENTS; i++)
{
@ -3712,14 +3665,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
Gv_Init();
C_AddDefaultDefinitions();
script = (instype *)Bcalloc(g_scriptSize, sizeof(instype));
// initprintf("script: %d\n",script);
if (!script || !label || !labelval || !labeltype || !constants)
{
initprintf("C_Compile(): ERROR: out of memory!\n");
g_numCompilerErrors++;
return;
}
script = (instype *)Xcalloc(g_scriptSize, sizeof(instype));
g_scriptPtr = script+1;
@ -3729,13 +3675,8 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
if (isfilename)
{
fs = Bstrlen(filenameortext);
mptr = (char *)Bmalloc(fs+1+4);
if (!mptr)
{
initprintf("C_Compile(): ERROR: out of memory!\n");
g_numCompilerErrors++;
return;
}
mptr = (char *)Xmalloc(fs+1+4);
Bmemcpy(mptr, filenameortext, fs+1);
fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/);
@ -3775,13 +3716,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
if (isfilename)
{
mptr = (char *)Bmalloc(fs+1);
if (!mptr)
{
initprintf("Failed allocating %d byte CON text buffer.\n", fs+1);
return;
}
mptr = (char *)Xmalloc(fs+1);
mptr[fs] = 0;
kread(fp, mptr, fs);
@ -3824,13 +3759,13 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
{
if (aGameVars[i].val.plValues)
{
aGameVars[i].val.plValues = (int32_t *)Brealloc(aGameVars[i].val.plValues, (1+MAXEVENTS+g_stateCount)*sizeof(int32_t));
aGameVars[i].val.plValues = (int32_t *)Xrealloc(aGameVars[i].val.plValues, (1+MAXEVENTS+g_stateCount)*sizeof(int32_t));
for (j=ostateCount; j<g_stateCount; j++)
aGameVars[i].val.plValues[1+MAXEVENTS+j] = aGameVars[i].lDefault;
}
else
{
aGameVars[i].val.plValues = (int32_t *)Bmalloc((1+MAXEVENTS+g_stateCount)*sizeof(int32_t));
aGameVars[i].val.plValues = (int32_t *)Xmalloc((1+MAXEVENTS+g_stateCount)*sizeof(int32_t));
for (j=0; j<(1+MAXEVENTS+g_stateCount); j++)
aGameVars[i].val.plValues[j] = aGameVars[i].lDefault;
}
@ -3855,7 +3790,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
}
/// for (i=MAXQUOTES-1; i>=0; i--)
/// if (ScriptQuotes[i] == NULL)
/// ScriptQuotes[i] = Bcalloc(MAXQUOTELEN,sizeof(uint8_t));
/// ScriptQuotes[i] = Xcalloc(MAXQUOTELEN,sizeof(uint8_t));
}
if (g_numCompilerErrors)
@ -4020,7 +3955,7 @@ void C_PrintErrorPosition()
return;
{
char *buf = (char *)Bmalloc(nchars+1);
char *buf = (char *)Xmalloc(nchars+1);
Bmemcpy(buf, b, nchars);
buf[nchars]=0;

View file

@ -518,13 +518,7 @@ skip_check:
}
// OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n", aGameArrays[j].szLabel, aGameArrays[j].size, asize);
aGameArrays[j].vals = Brealloc(aGameArrays[j].vals, sizeof(int32_t) * asize);
if (aGameArrays[j].vals == NULL)
{
aGameArrays[j].size = 0;
M32_ERROR("Out of memory!");
return 1;
}
aGameArrays[j].vals = Xrealloc(aGameArrays[j].vals, sizeof(int32_t) * asize);
aGameArrays[j].size = asize;
continue;

View file

@ -119,12 +119,12 @@ int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32
i = g_gameArrayCount;
if (aGameArrays[i].szLabel == NULL)
aGameArrays[i].szLabel = (char *)Bcalloc(MAXARRAYLABEL, sizeof(char));
aGameArrays[i].szLabel = (char *)Xcalloc(MAXARRAYLABEL, sizeof(char));
if (aGameArrays[i].szLabel != pszLabel)
Bstrcpy(aGameArrays[i].szLabel, pszLabel);
if (!(dwFlags & GAMEARRAY_TYPE_MASK))
aGameArrays[i].vals = (int32_t *)Bcalloc(asize, sizeof(int32_t));
aGameArrays[i].vals = (int32_t *)Xcalloc(asize, sizeof(int32_t));
else
aGameArrays[i].vals = arrayptr;
@ -182,7 +182,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
if ((aGameVars[i].dwFlags & GAMEVAR_SYSTEM) == 0)
{
if (aGameVars[i].szLabel == NULL)
aGameVars[i].szLabel = (char *)Bcalloc(MAXVARLABEL, sizeof(uint8_t));
aGameVars[i].szLabel = (char *)Xcalloc(MAXVARLABEL, sizeof(uint8_t));
if (aGameVars[i].szLabel != pszLabel)
Bstrcpy(aGameVars[i].szLabel,pszLabel);
aGameVars[i].dwFlags = dwFlags;
@ -209,7 +209,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
if (aGameVars[i].dwFlags & GAMEVAR_PERBLOCK)
{
if (!aGameVars[i].val.plValues)
aGameVars[i].val.plValues = (int32_t *)Bcalloc(1+MAXEVENTS+g_stateCount, sizeof(int32_t));
aGameVars[i].val.plValues = (int32_t *)Xcalloc(1+MAXEVENTS+g_stateCount, sizeof(int32_t));
for (j=0; j<1+MAXEVENTS+g_stateCount; j++)
aGameVars[i].val.plValues[j] = lValue;
}

View file

@ -1243,11 +1243,7 @@ int32_t MIDI_PlaySong
}
_MIDI_TrackMemSize = _MIDI_NumTracks * sizeof(track);
_MIDI_TrackPtr = (track *)Bmalloc(_MIDI_TrackMemSize);
if (_MIDI_TrackPtr == NULL)
{
return(MIDI_NoMemory);
}
_MIDI_TrackPtr = (track *)Xmalloc(_MIDI_TrackMemSize);
CurrentTrack = _MIDI_TrackPtr;
numtracks = _MIDI_NumTracks;

View file

@ -266,8 +266,7 @@ void Net_Connect(const char *srvaddr)
char *addrstr = NULL;
int32_t i;
char *oursrvaddr = Bstrdup(srvaddr);
if (!oursrvaddr) G_GameExit("OUT OF MEMORY");
char *oursrvaddr = Xstrdup(srvaddr);
Net_Disconnect();
@ -827,11 +826,11 @@ void Net_ReceiveNewPlayer(uint8_t *pbuf, int32_t packbufleng)
if (!g_player[pbuf[4]].ps)
{
g_player[pbuf[4]].ps = (DukePlayer_t *) Bcalloc(1,sizeof(DukePlayer_t));
g_player[pbuf[4]].ps = (DukePlayer_t *) Xcalloc(1,sizeof(DukePlayer_t));
}
if (!g_player[pbuf[4]].sync)
{
g_player[pbuf[4]].sync = (input_t *) Bcalloc(1,sizeof(input_t));
g_player[pbuf[4]].sync = (input_t *) Xcalloc(1,sizeof(input_t));
}
}
@ -1019,7 +1018,7 @@ netmapstate_t *Net_GetRevision(uint8_t revision, uint8_t cancreate)
if (cancreate && g_mapStateHistory[revision] == NULL)
{
g_mapStateHistory[revision] = (netmapstate_t *) Bcalloc(1, sizeof(netmapstate_t));
g_mapStateHistory[revision] = (netmapstate_t *) Xcalloc(1, sizeof(netmapstate_t));
Bmemset(g_mapStateHistory[revision], 0, sizeof(netmapstate_t));
}

View file

@ -1627,11 +1627,11 @@ int32_t registerosdcommands(void)
// if (!Bstrcmp(gamefunctions[i],"Show_Console")) continue;
Bsprintf(tempbuf,"gamefunc_%s",gamefunctions[i]);
t = Bstrdup(tempbuf);
t = Xstrdup(tempbuf);
for (j=Bstrlen(t); j>=0; j--)
t[j] = Btolower(t[j]);
Bstrcat(tempbuf,": game button");
OSD_RegisterFunction(t,Bstrdup(tempbuf),osdcmd_button);
OSD_RegisterFunction(t, Xstrdup(tempbuf), osdcmd_button);
}
OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);

View file

@ -1024,10 +1024,7 @@ static inline void prelevel(char g)
{
int32_t i, nexti, j, startwall, endwall;
int32_t switchpicnum;
uint8_t *tagbitmap = (uint8_t *)Bcalloc(65536>>3, 1);
if (tagbitmap==NULL)
G_GameExit("OUT OF MEMORY in prelevel()");
uint8_t *tagbitmap = (uint8_t *)Xcalloc(65536>>3, 1);
Bmemset(show2dsector, 0, sizeof(show2dsector));
#ifdef LEGACY_ROR
@ -1734,7 +1731,7 @@ static void realloc_and_copy_musicfn(int32_t level_number, const char *levnamebu
char **musicfn = altp ? &MapInfo[level_number].alt_musicfn : &MapInfo[level_number].musicfn;
int32_t dastrlen = Bstrlen(levnamebuf);
*musicfn = (char *)Brealloc(*musicfn, dastrlen+1);
*musicfn = (char *)Xrealloc(*musicfn, dastrlen+1);
Bstrcpy(*musicfn, levnamebuf);
}
@ -1846,9 +1843,9 @@ int32_t G_EnterLevel(int32_t g)
if (G_HaveUserMap())
{
if (MapInfo[mii].filename == NULL)
MapInfo[mii].filename = (char *)Bcalloc(BMAX_PATH, sizeof(uint8_t));
MapInfo[mii].filename = (char *)Xcalloc(BMAX_PATH, sizeof(uint8_t));
if (MapInfo[mii].name == NULL)
MapInfo[mii].name = Bstrdup("User Map");
MapInfo[mii].name = Xstrdup("User Map");
}
else
{

View file

@ -69,27 +69,15 @@ static int32_t RTS_AddFile(const char *filename)
header.infotableofs = B_LITTLE32(header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
fileinfo = fileinfoo = (filelump_t *)Bmalloc(length);
if (!fileinfo)
{
initprintf("RTS file could not allocate header info\n");
kclose(handle);
return -1;
}
fileinfo = fileinfoo = (filelump_t *)Xmalloc(length);
klseek(handle, header.infotableofs, SEEK_SET);
kread(handle, fileinfo, length);
{
lumpinfo_t *lump_p = (lumpinfo_t *)Brealloc(
lumpinfo_t *lump_p = (lumpinfo_t *)Xrealloc(
rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));
if (!lump_p)
{
kclose(handle);
return -1;
}
rts_lumpinfo = lump_p;
}
@ -125,7 +113,7 @@ void RTS_Init(const char *filename)
if (rts_numlumps == 0)
return;
rts_lumpcache = (void **)Bcalloc(rts_numlumps, sizeof(rts_lumpcache[0]));
rts_lumpcache = (void **)Xcalloc(rts_numlumps, sizeof(rts_lumpcache[0]));
RTS_Started = TRUE;
}

View file

@ -1121,10 +1121,7 @@ static void sv_makevarspec()
numsavedarrays += !(aGameArrays[i].dwFlags & GAMEARRAY_READONLY); // SYSTEM_GAMEARRAY
Bfree(svgm_vars);
svgm_vars = (dataspec_t *)Bmalloc((numsavedvars+numsavedarrays+2)*sizeof(dataspec_t));
if (svgm_vars == NULL)
G_GameExit("OUT OF MEMORY in sv_makevarspec()\n");
svgm_vars = (dataspec_t *)Xmalloc((numsavedvars+numsavedarrays+2)*sizeof(dataspec_t));
svgm_vars[0].flags = DS_STRING;
svgm_vars[0].ptr = magic;
@ -1176,21 +1173,15 @@ void sv_freemem()
Bfree(svdiff), svdiff=NULL;
}
static int32_t doallocsnap(int32_t allocinit)
static void SV_AllocSnap(int32_t allocinit)
{
sv_freemem();
svsnapshot = (uint8_t *)Bmalloc(svsnapsiz);
svsnapshot = (uint8_t *)Xmalloc(svsnapsiz);
if (allocinit)
svinitsnap = (uint8_t *)Bmalloc(svsnapsiz);
svinitsnap = (uint8_t *)Xmalloc(svsnapsiz);
svdiffsiz = svsnapsiz; // theoretically it's less than could be needed in the worst case, but practically it's overkill
svdiff = (uint8_t *)Bmalloc(svdiffsiz);
if (svsnapshot==NULL || (allocinit && svinitsnap==NULL) || svdiff==NULL)
{
sv_freemem();
return 1;
}
return 0;
svdiff = (uint8_t *)Xmalloc(svdiffsiz);
}
@ -1300,11 +1291,7 @@ int32_t sv_saveandmakesnapshot(FILE *fil, int8_t spot, int8_t recdiffsp, int8_t
uint8_t *p;
// demo
if (doallocsnap(0))
{
OSD_Printf("sv_saveandmakesnapshot: failed allocating memory.\n");
return 1;
}
SV_AllocSnap(0);
p = dosaveplayer2(fil, svsnapshot);
if (p != svsnapshot+svsnapsiz)
@ -1419,11 +1406,7 @@ int32_t sv_loadsnapshot(int32_t fil, int32_t spot, savehead_t *h)
svsnapsiz = h->snapsiz;
if (doallocsnap(1))
{
OSD_Printf("sv_loadsnapshot: failed allocating memory.\n");
return 4;
}
SV_AllocSnap(1);
p = svsnapshot;
i = doloadplayer2(fil, &p);
@ -1588,7 +1571,7 @@ static void sv_prescriptload_once()
{
if (script)
Bfree(script);
script = (intptr_t *)Bmalloc(g_scriptSize * sizeof(script[0]));
script = (intptr_t *)Xmalloc(g_scriptSize * sizeof(script[0]));
}
static void sv_postscript_once()
{
@ -1636,7 +1619,7 @@ static void sv_postanimateptr()
static void sv_prequote()
{
if (!savegame_quotes)
savegame_quotes = (char (*)[MAXQUOTELEN])Bcalloc(MAXQUOTES, MAXQUOTELEN);
savegame_quotes = (char (*)[MAXQUOTELEN])Xcalloc(MAXQUOTES, MAXQUOTELEN);
}
static void sv_quotesave()
{
@ -1664,7 +1647,7 @@ static void sv_quoteload()
static void sv_prequoteredef()
{
// "+1" needed for dfwrite which doesn't handle the src==NULL && cnt==0 case
savegame_quoteredefs = (char (*)[MAXQUOTELEN])Bcalloc(g_numQuoteRedefinitions+1, MAXQUOTELEN);
savegame_quoteredefs = (char (*)[MAXQUOTELEN])Xcalloc(g_numQuoteRedefinitions+1, MAXQUOTELEN);
}
static void sv_quoteredefsave()
{
@ -1679,7 +1662,7 @@ static void sv_quoteredefload()
for (i=0; i<g_numQuoteRedefinitions; i++)
{
if (!ScriptQuoteRedefinitions[i])
ScriptQuoteRedefinitions[i] = (char *)Bcalloc(1,MAXQUOTELEN);
ScriptQuoteRedefinitions[i] = (char *)Xcalloc(1,MAXQUOTELEN);
Bmemcpy(ScriptQuoteRedefinitions[i], savegame_quoteredefs[i], MAXQUOTELEN);
}
}
@ -1831,9 +1814,7 @@ static int32_t El_ReadSaveCode(int32_t fil)
if (slen > 0)
{
char *svcode = (char *)Bmalloc(slen+1);
if (svcode == NULL)
G_GameExit("OUT OF MEMORY in doloadplayer2().");
char *svcode = (char *)Xmalloc(slen+1);
if (kdfread(svcode, 1, slen, fil) != slen) // cnt and sz swapped
{

View file

@ -192,9 +192,7 @@ int32_t MUSIC_Init(int32_t SoundCard, int32_t Address)
sz = (numargs+2)*sizeof(char *) + (c-command+1);
sz = ((sz+pagesize-1)/pagesize)*pagesize;
#if defined(__APPLE__) || defined(__ANDROID__)
external_midi_argv = Bcalloc(1,sz+pagesize);
if (!external_midi_argv)
goto fallback;
external_midi_argv = Xcalloc(1,sz+pagesize);
external_midi_argv = (char **)((intptr_t)external_midi_argv + (pagesize-(((intptr_t)external_midi_argv)&(pagesize-1))));
#else
if (posix_memalign((void **)&external_midi_argv, pagesize, sz))

View file

@ -203,7 +203,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel)
if (MapInfo[sel].alt_musicfn != NULL)
alt = fn = MapInfo[sel].alt_musicfn;
testfn = (char *) Bmalloc(strlen(fn) + 6);
testfn = (char *)Xmalloc(strlen(fn) + 6);
strcpy(testfn, fn);
extension = strrchr(testfn, '.');
@ -259,7 +259,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel)
}
Bfree(MusicPtr); // in case the following allocation was never freed
MusicPtr = (char *)Bmalloc(MusicLen);
MusicPtr = (char *)Xmalloc(MusicLen);
g_musicSize = kread(fp, (char *)MusicPtr, MusicLen);
if (g_musicSize != MusicLen)