- audit malloc usage. now everything checks the return value :)

This commit is contained in:
Adam Olsen 2001-10-24 22:50:06 +00:00
parent 133ce647fb
commit 3bba5398ba
32 changed files with 109 additions and 29 deletions

View file

@ -80,6 +80,10 @@ SNDDMA_Init (void)
shm->samples = 16384; // mono samples in buffer shm->samples = 16384; // mono samples in buffer
shm->speed = 44100; shm->speed = 44100;
shm->buffer = malloc (shm->samples * shm->channels * shm->samplebits / 8); shm->buffer = malloc (shm->samples * shm->channels * shm->samplebits / 8);
if (!shm->buffer) {
Sys_Printf ("SNDDMA_Init: memory allocation failure\n");
return 0;
}
Sys_Printf ("%5d stereo\n", shm->channels - 1); Sys_Printf ("%5d stereo\n", shm->channels - 1);
Sys_Printf ("%5d samples\n", shm->samples); Sys_Printf ("%5d samples\n", shm->samples);

View file

@ -72,6 +72,8 @@ Mod_Fullbright (byte * skin, int width, int height, char *name)
// ptexels = Hunk_Alloc(s); // ptexels = Hunk_Alloc(s);
ptexels = malloc (pixels); ptexels = malloc (pixels);
if (!ptexels)
Sys_Error ("Mod_Fullbright: Memory Allocation Failure\n");
if (Mod_CalcFullbright (skin, ptexels, pixels)) { if (Mod_CalcFullbright (skin, ptexels, pixels)) {
Sys_DPrintf ("FB Model ID: '%s'\n", name); Sys_DPrintf ("FB Model ID: '%s'\n", name);
texnum = GL_LoadTexture (name, width, height, ptexels, true, true, 1); texnum = GL_LoadTexture (name, width, height, ptexels, true, true, 1);

View file

@ -244,6 +244,8 @@ Cmd_StuffCmds_f (void)
// pull out the commands // pull out the commands
build = malloc (s + 1); build = malloc (s + 1);
if (!build)
Sys_Error ("Cmd_StuffCmds_f: Memory Allocation Failure\n");
build[0] = 0; build[0] = 0;
for (i = 0; i < s - 1; i++) { for (i = 0; i < s - 1; i++) {
@ -339,16 +341,6 @@ Cmd_Echo_f (void)
Creates a new command that executes a command string (possibly ; seperated) Creates a new command that executes a command string (possibly ; seperated)
*/ */
char *
CopyString (char *in)
{
char *out;
out = malloc (strlen (in) + 1);
strcpy (out, in);
return out;
}
void void
Cmd_Alias_f (void) Cmd_Alias_f (void)
{ {
@ -384,6 +376,8 @@ Cmd_Alias_f (void)
// copy the rest of the command line // copy the rest of the command line
cmd = malloc (strlen (Cmd_Args (1)) + 2);// can never be longer cmd = malloc (strlen (Cmd_Args (1)) + 2);// can never be longer
if (!cmd)
Sys_Error ("Cmd_Alias_f: Memory Allocation Failure\n");
cmd[0] = 0; // start out with a null string cmd[0] = 0; // start out with a null string
c = Cmd_Argc (); c = Cmd_Argc ();
for (i = 2; i < c; i++) { for (i = 2; i < c; i++) {
@ -545,6 +539,8 @@ Cmd_AddCommand (const char *cmd_name, xcommand_t function, const char *descripti
} }
cmd = malloc (sizeof (cmd_function_t)); cmd = malloc (sizeof (cmd_function_t));
if (!cmd)
Sys_Error ("Cmd_AddCommand: Memory_Allocation_Failure\n");
cmd->name = cmd_name; cmd->name = cmd_name;
cmd->function = function; cmd->function = function;
cmd->description = description; cmd->description = description;
@ -648,6 +644,8 @@ Cmd_CompleteBuildList (const char *partial)
len = strlen(partial); len = strlen(partial);
buf = malloc(sizeofbuf + sizeof (char *)); buf = malloc(sizeofbuf + sizeof (char *));
if (!buf)
Sys_Error ("Cmd_CompleteBuildList: Memory Allocation Failure\n");
// Loop through the alias list and print all matches // Loop through the alias list and print all matches
for (cmd = cmd_functions; cmd; cmd = cmd->next) for (cmd = cmd_functions; cmd; cmd = cmd->next)
if (!strncasecmp(partial, cmd->name, len)) if (!strncasecmp(partial, cmd->name, len))
@ -734,6 +732,8 @@ Cmd_CompleteAliasBuildList (const char *partial)
len = strlen(partial); len = strlen(partial);
buf = malloc(sizeofbuf + sizeof (char *)); buf = malloc(sizeofbuf + sizeof (char *));
if (!buf)
Sys_Error ("Cmd_CompleteAliasBuildList: Memory Allocation Failure\n");
// Loop through the alias list and print all matches // Loop through the alias list and print all matches
for (alias = cmd_alias; alias; alias = alias->next) for (alias = cmd_alias; alias; alias = alias->next)
if (!strncasecmp(partial, alias->name, len)) if (!strncasecmp(partial, alias->name, len))

View file

@ -214,6 +214,8 @@ Cvar_CompleteBuildList (const char *partial)
len = strlen(partial); len = strlen(partial);
buf = malloc(sizeofbuf + sizeof (char *)); buf = malloc(sizeofbuf + sizeof (char *));
if (!buf)
Sys_Error ("Cvar_CompleteBuildList: Memory Allocation Failure\n");
// Loop through the alias list and print all matches // Loop through the alias list and print all matches
for (cvar = cvar_vars; cvar; cvar = cvar->next) for (cvar = cvar_vars; cvar; cvar = cvar->next)
if (!strncasecmp(partial, cvar->name, len)) if (!strncasecmp(partial, cvar->name, len))

View file

@ -879,6 +879,8 @@ COM_LoadGameDirectory (const char *dir)
} }
pakfiles[count] = malloc (FNAME_SIZE); pakfiles[count] = malloc (FNAME_SIZE);
if (!pakfiles[count])
Sys_Error ("COM_LoadGameDirectory: MemoryAllocationFailure\n");
snprintf (pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir, snprintf (pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
dirent->d_name); dirent->d_name);
pakfiles[count][FNAME_SIZE - 1] = '\0'; pakfiles[count][FNAME_SIZE - 1] = '\0';

View file

@ -383,8 +383,11 @@ Qgetline (VFile *file)
static char *buf = 0; static char *buf = 0;
int len; int len;
if (!buf) if (!buf) {
buf = malloc (size); buf = malloc (size);
if (!buf)
return 0;
}
if (!Qgets (file, buf, size)) if (!Qgets (file, buf, size))
return 0; return 0;

View file

@ -108,6 +108,8 @@ LoadTGA (VFile *fin)
numPixels = columns * rows; numPixels = columns * rows;
targa_rgba = malloc (numPixels * 4); targa_rgba = malloc (numPixels * 4);
if (!targa_rgba)
Sys_Error ("LoadTGA: Memory Allocation Failure\n");
if (targa_header.id_length != 0) if (targa_header.id_length != 0)
Qseek (fin, targa_header.id_length, SEEK_CUR); // skip TARGA image Qseek (fin, targa_header.id_length, SEEK_CUR); // skip TARGA image

View file

@ -621,6 +621,8 @@ SCR_ScreenShot_f (void)
return; return;
} }
buffer = malloc (glwidth * glheight * 3); buffer = malloc (glwidth * glheight * 3);
if (!buffer)
Sys_Error ("SCR_ScreenShot_f: Memory Allocation Failure\n");
qfglReadPixels (glx, gly, glwidth, glheight, GL_BGR_EXT, GL_UNSIGNED_BYTE, qfglReadPixels (glx, gly, glwidth, glheight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
buffer); buffer);
WriteTGAfile (pcxname, buffer, glwidth, glheight); WriteTGAfile (pcxname, buffer, glwidth, glheight);

View file

@ -518,6 +518,8 @@ GL_Upload8 (byte * data, int width, int height, qboolean mipmap, qboolean alpha)
s = width * height; s = width * height;
trans = malloc (s * sizeof (unsigned int)); trans = malloc (s * sizeof (unsigned int));
if (!trans)
Sys_Error ("GL_Upload8: Memory Allocation Failure\n");
// if there are no transparent pixels, make it a 3 component // if there are no transparent pixels, make it a 3 component
// texture even if it was specified as otherwise // texture even if it was specified as otherwise

View file

@ -28,6 +28,8 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "QF/sys.h"
#include "fbset.h" #include "fbset.h"
struct file; struct file;
@ -406,6 +408,8 @@ AddVideoMode (const struct VideoMode *vmode)
Die("%s:%d: Duplicate mode name `%s'\n", Opt_modedb, line, Die("%s:%d: Duplicate mode name `%s'\n", Opt_modedb, line,
vmode->name); vmode->name);
vmode2 = malloc(sizeof(struct VideoMode)); vmode2 = malloc(sizeof(struct VideoMode));
if (!vmode2)
Sys_Error ("AddVideoMode: Memory Allocation Failure\n");
*vmode2 = *vmode; *vmode2 = *vmode;
if (!FillScanRates(vmode2)) if (!FillScanRates(vmode2))
Die("%s:%d: Bad video mode `%s'\n", Opt_modedb, line, vmode2->name); Die("%s:%d: Bad video mode `%s'\n", Opt_modedb, line, vmode2->name);

View file

@ -199,6 +199,8 @@ VID_MakeColormaps (int fullbrights, byte *pal)
vid.colormap8 = malloc (256*VID_GRADES * sizeof (byte)); vid.colormap8 = malloc (256*VID_GRADES * sizeof (byte));
vid.colormap16 = malloc (256*VID_GRADES * sizeof (short)); vid.colormap16 = malloc (256*VID_GRADES * sizeof (short));
vid.colormap32 = malloc (256*VID_GRADES * sizeof (int)); vid.colormap32 = malloc (256*VID_GRADES * sizeof (int));
if (!vid.colormap8 || !vid.colormap16 || !vid.colormap32)
Sys_Error ("VID_MakeColormaps: Memory Allocation Failure\n");
VID_MakeColormap8(vid.colormap8, pal); VID_MakeColormap8(vid.colormap8, pal);
VID_MakeColormap16(vid.colormap16, pal); VID_MakeColormap16(vid.colormap16, pal);
VID_MakeColormap32(vid.colormap32, pal); VID_MakeColormap32(vid.colormap32, pal);

View file

@ -267,6 +267,8 @@ VID_InitModes (void)
/* Get complete information on all modes */ /* Get complete information on all modes */
num_modes = vga_lastmodenumber () + 1; num_modes = vga_lastmodenumber () + 1;
modes = malloc (num_modes * sizeof (vga_modeinfo)); modes = malloc (num_modes * sizeof (vga_modeinfo));
if (!modes)
Sys_Error ("VID_InitModes: Memory Allocation Failure\n");
for (i = 0; i < num_modes; i++) { for (i = 0; i < num_modes; i++) {
if (vga_hasmode (i)) { if (vga_hasmode (i)) {
memcpy (&modes[i], vga_getmodeinfo (i), sizeof (vga_modeinfo)); memcpy (&modes[i], vga_getmodeinfo (i), sizeof (vga_modeinfo));

View file

@ -294,6 +294,7 @@ static void
ResetFrameBuffer (void) ResetFrameBuffer (void)
{ {
int mem, pwidth; int mem, pwidth;
char *buf;
if (x_framebuffer[0]) { if (x_framebuffer[0]) {
XDestroyImage (x_framebuffer[0]); XDestroyImage (x_framebuffer[0]);
@ -304,10 +305,13 @@ ResetFrameBuffer (void)
if (pwidth == 3) if (pwidth == 3)
pwidth = 4; pwidth = 4;
mem = ((vid.width * pwidth + 7) & ~7) * vid.height; mem = ((vid.width * pwidth + 7) & ~7) * vid.height;
buf = malloc (mem);
if (!buf)
Sys_Error ("ResetFrameBuffer: Memory Allocation Failure\n");
// allocate new screen buffer // allocate new screen buffer
x_framebuffer[0] = XCreateImage (x_disp, x_vis, x_visinfo->depth, x_framebuffer[0] = XCreateImage (x_disp, x_vis, x_visinfo->depth,
ZPixmap, 0, malloc (mem), vid.width, ZPixmap, 0, buf, vid.width,
vid.height, 32, 0); vid.height, 32, 0);
if (!x_framebuffer[0]) { if (!x_framebuffer[0]) {

View file

@ -793,12 +793,16 @@ Host_InitVCR (quakeparms_t *parms)
Qread (vcrFile, &com_argc, sizeof (int)); Qread (vcrFile, &com_argc, sizeof (int));
com_argv = malloc (com_argc * sizeof (char *)); com_argv = malloc (com_argc * sizeof (char *));
if (!com_argv)
Sys_Error ("Host_InitVCR: Memory Allocation Failure\n");
com_argv[0] = parms->argv[0]; com_argv[0] = parms->argv[0];
for (i = 0; i < com_argc; i++) { for (i = 0; i < com_argc; i++) {
Qread (vcrFile, &len, sizeof (int)); Qread (vcrFile, &len, sizeof (int));
p = malloc (len); p = malloc (len);
if (!p)
Sys_Error ("Host_InitVCR: Memory Allocation Failure\n");
Qread (vcrFile, p, len); Qread (vcrFile, p, len);
com_argv[i + 1] = p; com_argv[i + 1] = p;
} }

View file

@ -100,6 +100,8 @@ locs_add (vec3_t location, const char *name)
num = locations_count - 1; num = locations_count - 1;
locations[num] = malloc (sizeof (location_t)); locations[num] = malloc (sizeof (location_t));
if (!locations[num])
Sys_Error ("locs_add: Memory Allocation Failure\n");
locations[num]->loc[0] = location[0]; locations[num]->loc[0] = location[0];
locations[num]->loc[1] = location[1]; locations[num]->loc[1] = location[1];

View file

@ -132,7 +132,8 @@ main (int argc, const char **argv)
memset (&parms, 0, sizeof (parms)); memset (&parms, 0, sizeof (parms));
parms.memsize = 16384 * 1024; parms.memsize = 16384 * 1024;
parms.membase = malloc (parms.memsize); if (!(parms.membase = malloc (parms.memsize)))
Sys_Error ("Can't allocate %d\n", parms.memsize);
#if 0 #if 0
_getcwd (cwd, sizeof (cwd)); _getcwd (cwd, sizeof (cwd));
if (cwd[Q_strlen (cwd) - 1] == '\\') if (cwd[Q_strlen (cwd) - 1] == '\\')

View file

@ -50,6 +50,7 @@ static const char rcsid[] =
#include "QF/msg.h" #include "QF/msg.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sound.h" #include "QF/sound.h"
#include "QF/sys.h"
#include "QF/teamplay.h" #include "QF/teamplay.h"
#include "QF/va.h" #include "QF/va.h"
#include "QF/vfile.h" #include "QF/vfile.h"
@ -576,6 +577,8 @@ CL_StartUpload (byte * data, int size)
Con_DPrintf ("Upload starting of %d...\n", size); Con_DPrintf ("Upload starting of %d...\n", size);
upload_data = malloc (size); upload_data = malloc (size);
if (!upload_data)
Sys_Error ("CL_StartUpload: Memory Allocation Failure\n");
memcpy (upload_data, data, size); memcpy (upload_data, data, size);
upload_size = size; upload_size = size;
upload_pos = 0; upload_pos = 0;

View file

@ -128,6 +128,8 @@ SL_Add (server_entry_t *start, char *ip, char *desc)
start->next = 0; start->next = 0;
start->server = malloc (strlen (ip) + 1); start->server = malloc (strlen (ip) + 1);
start->desc = malloc (strlen (desc ? desc : ip) + 1); start->desc = malloc (strlen (desc ? desc : ip) + 1);
if (!start->server || !start->desc)
Sys_Error ("SL_Add: Memory Allocation Failure\n");
strcpy (start->server, ip); strcpy (start->server, ip);
strcpy (start->desc, desc ? desc : ip); strcpy (start->desc, desc ? desc : ip);
start->status = NULL; start->status = NULL;
@ -143,6 +145,8 @@ SL_Add (server_entry_t *start, char *ip, char *desc)
p->next->prev = p; p->next->prev = p;
p->next->server = malloc (strlen (ip) + 1); p->next->server = malloc (strlen (ip) + 1);
p->next->desc = malloc (strlen (desc ? desc : ip) + 1); p->next->desc = malloc (strlen (desc ? desc : ip) + 1);
if (!p->next->server || !p->next->desc)
Sys_Error ("SL_Add: Memory Allocation Failure\n");
strcpy (p->next->server, ip); strcpy (p->next->server, ip);
strcpy (p->next->desc, desc ? desc : ip); strcpy (p->next->desc, desc ? desc : ip);
@ -186,6 +190,8 @@ SL_InsB (server_entry_t *start, server_entry_t *place, char *ip, char *desc)
new->server = malloc (strlen (ip) + 1); new->server = malloc (strlen (ip) + 1);
new->desc = malloc (strlen (desc) + 1); new->desc = malloc (strlen (desc) + 1);
if (!new->server || !new->desc)
Sys_Error ("SL_InsB: Memory Allocation Failure\n");
strcpy (new->server, ip); strcpy (new->server, ip);
strcpy (new->desc, desc); strcpy (new->desc, desc);
other = place->prev; other = place->prev;
@ -629,6 +635,8 @@ SL_LoadF (VFile *f, server_entry_t *start)
if ((st = gettokstart (line, 1, ' ')) != NULL) { if ((st = gettokstart (line, 1, ' ')) != NULL) {
len = gettoklen (line, 1, ' '); len = gettoklen (line, 1, ' ');
addr = malloc (len + 1); addr = malloc (len + 1);
if (!addr)
Sys_Error ("SL_LoadF: Memory Allocation Failure\n");
strncpy (addr, &line[0], len); strncpy (addr, &line[0], len);
addr[len] = '\0'; addr[len] = '\0';
if ((st = gettokstart (line, 2, ' '))) { if ((st = gettokstart (line, 2, ' '))) {

View file

@ -228,6 +228,9 @@ Sys_ConsoleInput (void)
if (clipText) { if (clipText) {
textCopied = textCopied =
malloc (GlobalSize (th) + 1); malloc (GlobalSize (th) + 1);
if (!textCopied)
Sys_Error ("Sys_ConsoleInput: "
"Memory Allocation Failure\n");
strcpy (textCopied, clipText); strcpy (textCopied, clipText);
// Substitutes a NULL for every token // Substitutes a NULL for every token
strtok (textCopied, "\n\r\b"); strtok (textCopied, "\n\r\b");

View file

@ -102,6 +102,8 @@ locs_add (vec3_t location, const char *name)
num = locations_count - 1; num = locations_count - 1;
locations[num] = malloc (sizeof (location_t)); locations[num] = malloc (sizeof (location_t));
if (!locations[num])
Sys_Error ("locs_add: Memory Allocation Failure\n");
locations[num]->loc[0] = location[0]; locations[num]->loc[0] = location[0];
locations[num]->loc[1] = location[1]; locations[num]->loc[1] = location[1];

View file

@ -842,7 +842,6 @@ SV_SendServerInfoChange (const char *key, const char *value)
Examine or change the serverinfo string Examine or change the serverinfo string
*/ */
char *CopyString (char *s);
void void
SV_Serverinfo_f (void) SV_Serverinfo_f (void)
{ {
@ -881,7 +880,6 @@ SV_Serverinfo_f (void)
Examine or change the serverinfo string Examine or change the serverinfo string
*/ */
char *CopyString (char *s);
void void
SV_Localinfo_f (void) SV_Localinfo_f (void)
{ {

View file

@ -99,8 +99,6 @@ char *COM_Parse (char *data);
extern char com_token[1024]; extern char com_token[1024];
extern qboolean com_eof; extern qboolean com_eof;
char *copystring(char *s);
void CRC_Init(unsigned short *crcvalue); void CRC_Init(unsigned short *crcvalue);
void CRC_ProcessByte(unsigned short *crcvalue, byte data); void CRC_ProcessByte(unsigned short *crcvalue, byte data);
unsigned short CRC_Value(unsigned short crcvalue); unsigned short CRC_Value(unsigned short crcvalue);

View file

@ -41,6 +41,8 @@
#include <direct.h> #include <direct.h>
#endif #endif
#include <QF/sys.h>
#include "cmdlib.h" #include "cmdlib.h"
#define PATHSEPERATOR '/' #define PATHSEPERATOR '/'
@ -152,16 +154,6 @@ ExpandPathAndArchive (char *path)
return expanded; return expanded;
} }
char *
copystring (char *s)
{
char *b;
b = malloc (strlen (s) + 1);
strcpy (b, s);
return b;
}
/* /*
I_FloatTime I_FloatTime
*/ */

View file

@ -43,6 +43,8 @@
#include <libc.h> #include <libc.h>
#endif #endif
#include <QF/sys.h>
#include "cmdlib.h" #include "cmdlib.h"
#define PATHSEPERATOR '/' #define PATHSEPERATOR '/'
@ -249,6 +251,8 @@ LoadFile (char *filename, void **bufferptr)
f = SafeOpenRead (filename); f = SafeOpenRead (filename);
length = FileLength (f); length = FileLength (f);
buffer = malloc (length + 1); buffer = malloc (length + 1);
if (!buffer)
Sys_Error ("LoadFile: Memory Allocation Failure\n");
((char *) buffer)[length] = 0; ((char *) buffer)[length] = 0;
SafeRead (f, buffer, length); SafeRead (f, buffer, length);
fclose (f); fclose (f);

View file

@ -33,6 +33,7 @@ static const char rcsid[] =
#include <stdlib.h> #include <stdlib.h>
#include <QF/mathlib.h> #include <QF/mathlib.h>
#include <QF/sys.h>
#include <QF/va.h> #include <QF/va.h>
#include "qfcc.h" #include "qfcc.h"
@ -286,6 +287,8 @@ new_label_expr (void)
expr_t *l = new_expr (); expr_t *l = new_expr ();
l->type = ex_label; l->type = ex_label;
l->e.label.name = malloc (len); l->e.label.name = malloc (len);
if (!l->e.label.name)
Sys_Error ("new_label_expr: Memory Allocation Failure\n");
sprintf (l->e.label.name, "$%s_%d", fname, lnum); sprintf (l->e.label.name, "$%s_%d", fname, lnum);
return l; return l;
} }
@ -472,6 +475,8 @@ do_op_string (int op, expr_t *e1, expr_t *e2)
case '+': case '+':
len = strlen (s1) + strlen (s2) + 1; len = strlen (s1) + strlen (s2) + 1;
buf = malloc (len); buf = malloc (len);
if (!buf)
Sys_Error ("do_op_string: Memory Allocation Failure\n");
strcpy (buf, s1); strcpy (buf, s1);
strcat (buf, s2); strcat (buf, s2);
e1->e.string_val = buf; e1->e.string_val = buf;
@ -1235,6 +1240,8 @@ function_expr (expr_t *e1, expr_t *e2)
expr_t *ret = new_expr (); expr_t *ret = new_expr ();
ret->type = ex_def; ret->type = ex_def;
ret->e.def = memcpy (malloc (sizeof (def_t)), &def_ret, sizeof (def_t)); ret->e.def = memcpy (malloc (sizeof (def_t)), &def_ret, sizeof (def_t));
if (!ret->e.def)
Sys_Error ("function_expr: Memory Allocation Failure\n");
ret->e.def->type = ftype->aux_type; ret->e.def->type = ftype->aux_type;
call->e.block.result = ret; call->e.block.result = ret;
} }

View file

@ -23,6 +23,7 @@ static const char rcsid[] =
# include "config.h" # include "config.h"
#endif #endif
#include <QF/hash.h> #include <QF/hash.h>
#include <QF/sys.h>
#include "qfcc.h" #include "qfcc.h"
@ -196,6 +197,8 @@ PR_FreeLocation (def_t *def)
if (!free_free_locs) { if (!free_free_locs) {
free_free_locs = malloc (256 * sizeof (locref_t)); free_free_locs = malloc (256 * sizeof (locref_t));
if (!free_free_locs)
Sys_Error ("PR_FreeLocation: Memory Allocation Failure\n");
for (loc = free_free_locs; loc - free_free_locs < 255; loc++) for (loc = free_free_locs; loc - free_free_locs < 255; loc++)
loc->next = loc + 1; loc->next = loc + 1;
loc->next = 0; loc->next = 0;

View file

@ -30,6 +30,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#include <QF/sys.h>
#include "qfcc.h" #include "qfcc.h"
@ -291,12 +292,16 @@ PR_FindType (type_t *type)
// allocate a new one // allocate a new one
check = malloc (sizeof (*check)); check = malloc (sizeof (*check));
if (!check)
Sys_Error ("PR_FindType: Memory Allocation Failure\n");
*check = *type; *check = *type;
check->next = pr.types; check->next = pr.types;
pr.types = check; pr.types = check;
// allocate a generic def for the type, so fields can reference it // allocate a generic def for the type, so fields can reference it
def = malloc (sizeof (def_t)); def = malloc (sizeof (def_t));
if (!check)
Sys_Error ("PR_FindType: Memory Allocation Failure\n");
def->name = "COMPLEX TYPE"; def->name = "COMPLEX TYPE";
def->type = check; def->type = check;
check->def = def; check->def = def;

View file

@ -32,6 +32,7 @@ static const char rcsid[] =
"$Id$"; "$Id$";
#include <QF/hash.h> #include <QF/hash.h>
#include <QF/sys.h>
#include "qfcc.h" #include "qfcc.h"
#include "scope.h" #include "scope.h"
#include "qc-parse.h" #include "qc-parse.h"
@ -320,6 +321,8 @@ void
add_frame_macro (char *token) add_frame_macro (char *token)
{ {
frame_t *frame = malloc (sizeof (frame_t)); frame_t *frame = malloc (sizeof (frame_t));
if (!frame)
Sys_Error ("add_frame_macro: Memory Allocation Failure\n");
frame->name = strdup (token); frame->name = strdup (token);
frame->num = frame_number++; frame->num = frame_number++;
@ -342,6 +345,8 @@ make_string (char *token)
pr_file_p = token; pr_file_p = token;
PR_LexString (); PR_LexString ();
str = malloc (pr_token_len + 1); str = malloc (pr_token_len + 1);
if (!str)
Sys_Error ("make_string: Memory Allocation Failure\n");
memcpy (str, pr_token, pr_token_len + 1); memcpy (str, pr_token, pr_token_len + 1);
return str; return str;
} }

View file

@ -32,7 +32,8 @@ static const char rcsid[] =
"$Id$"; "$Id$";
#include "qfcc.h" #include "qfcc.h"
#include "QF/hash.h" #include <QF/hash.h>
#include <QF/sys.h>
#define YYDEBUG 1 #define YYDEBUG 1
#define YYERROR_VERBOSE 1 #define YYERROR_VERBOSE 1
@ -841,6 +842,8 @@ scan_scope (hashtab_t *tab, def_t *scope)
for (def = scope->scope_next; def; def = def->scope_next) { for (def = scope->scope_next; def; def = def->scope_next) {
if (def->name && !def->removed) { if (def->name && !def->removed) {
def_state_t *ds = malloc (sizeof (def_state_t)); def_state_t *ds = malloc (sizeof (def_state_t));
if (!ds)
Sys_Error ("scan_scope: Memory Allocation Failure\n");
ds->def = def; ds->def = def;
ds->state = def->initialized; ds->state = def->initialized;
Hash_Add (tab, ds); Hash_Add (tab, ds);
@ -870,6 +873,8 @@ merge_local_inits (hashtab_t *dl_1, hashtab_t *dl_2)
(*ds)->def->initialized = (*ds)->state; (*ds)->def->initialized = (*ds)->state;
nds = malloc (sizeof (def_state_t)); nds = malloc (sizeof (def_state_t));
if (!nds)
Sys_Error ("merge_local_inits: Memory Allocation Failure\n");
nds->def = (*ds)->def; nds->def = (*ds)->def;
nds->state = (*ds)->state && d->state; nds->state = (*ds)->state && d->state;
Hash_Add (tab, nds); Hash_Add (tab, nds);

View file

@ -913,6 +913,7 @@ main (int argc, char **argv)
int p, crc; int p, crc;
double start, stop; double start, stop;
int no_cpp = 0; int no_cpp = 0;
void *mem;
start = Sys_DoubleTime (); start = Sys_DoubleTime ();
@ -1023,7 +1024,10 @@ main (int argc, char **argv)
printf ("debug file: %s\n", debugfile); printf ("debug file: %s\n", debugfile);
} }
PR_BeginCompilation (malloc (0x100000), 0x100000); mem = malloc (0x100000);
if (!mem)
Sys_Error ("main: Memory Allocation Failure\n");
PR_BeginCompilation (mem, 0x100000);
// compile all the files // compile all the files
while ((src = COM_Parse (src))) { while ((src = COM_Parse (src))) {

View file

@ -35,6 +35,7 @@ static const char rcsid[] =
#include <string.h> #include <string.h>
#include <QF/progs.h> #include <QF/progs.h>
#include <QF/sys.h>
#include "def.h" #include "def.h"
@ -105,6 +106,8 @@ fix_missing_globals (progs_t *pr, def_t *globals)
} }
progs = malloc (pr->progs_size + strings_size); progs = malloc (pr->progs_size + strings_size);
if (!progs)
Sys_Error ("fix_missing_globals: Memory Allocation Failure\n");
memcpy (progs, pr->progs, pr->progs_size); memcpy (progs, pr->progs, pr->progs_size);
offs = progs->ofs_strings + progs->numstrings; offs = progs->ofs_strings + progs->numstrings;

View file

@ -67,6 +67,8 @@ main ()
Cvar_Init_Hash (); Cvar_Init_Hash ();
Cmd_Init_Hash (); Cmd_Init_Hash ();
membase = malloc (memsize); membase = malloc (memsize);
if (!membase)
Sys_Error ("Memory Allocation Failure\n");
Memory_Init (membase, memsize); Memory_Init (membase, memsize);
Cvar_Init (); Cvar_Init ();
Cbuf_Init (); Cbuf_Init ();