Restore Q_* alloc features

This commit is contained in:
Steam Deck User 2023-02-02 12:21:24 -05:00
parent 688f57bab1
commit 9c0d864012

View file

@ -382,6 +382,68 @@ bytecopy:
return (dst);
}
/*
===================
Q_malloc
Use it instead of malloc so that if memory allocation fails,
the program exits with a message saying there's not enough memory
instead of crashing after trying to use a NULL pointer
===================
*/
void *Q_malloc (size_t size)
{
void *p;
if (!(p = malloc(size)))
Sys_Error ("Not enough memory free; check disk space");
return p;
}
/*
===================
Q_calloc
===================
*/
void *Q_calloc (size_t n, size_t size)
{
void *p;
if (!(p = calloc(n, size)))
Sys_Error ("Not enough memory free; check disk space");
return p;
}
/*
===================
Q_realloc
===================
*/
void *Q_realloc (void *ptr, size_t size)
{
void *p;
if (!(p = realloc(ptr, size)))
Sys_Error ("Not enough memory free; check disk space");
return p;
}
/*
===================
Q_strdup
===================
*/
void *Q_strdup (const char *str)
{
char *p;
if (!(p = strdup(str)))
Sys_Error ("Not enough memory free; check disk space");
return p;
}
/*
==============================================================================