Skip to content

Commit

Permalink
More out of memory checks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Jul 15, 2024
1 parent c3c369f commit c50ccd1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
13 changes: 9 additions & 4 deletions Quake/gl_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -1783,10 +1783,15 @@ Mod_FindUsedTextures
*/
static void Mod_FindUsedTextures (qmodel_t *mod)
{
msurface_t *s;
int i, count;
int ofs[TEXTYPE_COUNT];
uint32_t *inuse = (uint32_t *) calloc (BITARRAY_DWORDS (mod->numtextures), sizeof (uint32_t));
msurface_t *s;
int i, count;
int ofs[TEXTYPE_COUNT];
uint32_t *inuse;

inuse = (uint32_t *) calloc (BITARRAY_DWORDS (mod->numtextures), sizeof (uint32_t));
if (!inuse)
Sys_Error ("Mod_FindUsedTextures: out of memory (%d bits)", mod->numtextures);

memset (ofs, 0, sizeof(ofs));
for (i = 0, s = mod->surfaces + mod->firstmodelsurface; i < mod->nummodelsurfaces; i++, s++)
{
Expand Down
2 changes: 2 additions & 0 deletions Quake/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ typedef struct stdio_buffer_s {
static stdio_buffer_t *Buf_Alloc(FILE *f)
{
stdio_buffer_t *buf = (stdio_buffer_t *) calloc(1, sizeof(stdio_buffer_t));
if (!buf)
Sys_Error ("Buf_Alloc: out of memory");
buf->f = f;
return buf;
}
Expand Down
2 changes: 2 additions & 0 deletions Quake/r_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ void GL_BuildLightmaps (void)
);

lightmap_data = (unsigned *) calloc (lmsize, sizeof (*lightmap_data));
if (!lightmap_data)
Sys_Error ("GL_BuildLightmaps: out of memory on %" SDL_PRIu64 " bytes", (uint64_t)(lmsize * sizeof (*lightmap_data)));

// compute offsets for each lightmap block
for (i=0; i<lightmap_count; i++)
Expand Down
5 changes: 4 additions & 1 deletion Quake/snd_mix.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ static void S_UpdateFilter(filter_t *filter, int M, float f_c)
filter->kernelsize = (M + 1) + 16 - ((M + 1) % 16);
filter->memory = (float *) calloc(filter->kernelsize, sizeof(float));
filter->kernel = (float *) calloc(filter->kernelsize, sizeof(float));


if (!filter->memory || !filter->kernel)
Sys_Error ("S_UpdateFilter: out of memory (%d bytes)", filter->kernelsize * sizeof (float));

S_MakeBlackmanWindowKernel(filter->kernel, M, f_c);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Quake/sys_sdl_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ findfile_t *Sys_FindFirst (const char *dir, const char *ext)
}

ret = (unixfindfile_t *) calloc (1, sizeof (unixfindfile_t));
if (!ret)
Sys_Error ("Sys_FindFirst: out of memory");
ret->handle = handle;
ret->data = data;
q_strlcpy (ret->filter, ext, sizeof (ret->filter));
Expand Down
2 changes: 2 additions & 0 deletions Quake/sys_sdl_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ findfile_t *Sys_FindFirst (const char *dir, const char *ext)
return NULL;

ret = (winfindfile_t *) calloc (1, sizeof (winfindfile_t));
if (!ret)
Sys_Error ("Sys_FindFirst: out of memory");
ret->handle = handle;
ret->data = data;
Sys_FillFindData (ret);
Expand Down

0 comments on commit c50ccd1

Please sign in to comment.