diff --git a/tools/qfcc/include/linker.h b/tools/qfcc/include/linker.h index 1a28f9d93..361644085 100644 --- a/tools/qfcc/include/linker.h +++ b/tools/qfcc/include/linker.h @@ -33,8 +33,8 @@ #define __linker_h void linker_begin (void); -void linker_add_object_file (const char *filename); -void linker_add_lib (const char *libname); +int linker_add_object_file (const char *filename); +int linker_add_lib (const char *libname); struct qfo_s *linker_finish (void); #endif//__linker_h diff --git a/tools/qfcc/source/linker.c b/tools/qfcc/source/linker.c index b420abe77..6a6a3e50c 100644 --- a/tools/qfcc/source/linker.c +++ b/tools/qfcc/source/linker.c @@ -566,14 +566,14 @@ linker_add_qfo (qfo_t *qfo) add_lines (qfo); } -void +int linker_add_object_file (const char *filename) { qfo_t *qfo; qfo = qfo_open (filename); if (!qfo) - return; + return 1; if (options.verbosity >= 2) puts (filename); @@ -581,9 +581,10 @@ linker_add_object_file (const char *filename) linker_add_qfo (qfo); qfo_delete (qfo); + return 0; } -void +int linker_add_lib (const char *libname) { pack_t *pack = pack_open (libname); @@ -591,7 +592,7 @@ linker_add_lib (const char *libname) int did_something; if (!pack) - return; + return 1; do { did_something = 0; for (i = 0; i < pack->numfiles; i++) { @@ -606,6 +607,9 @@ linker_add_lib (const char *libname) Qclose (f); close (fd); + if (!qfo) + return 1; + for (j = 0; j < qfo->num_defs; j++) { qfo_def_t *def = qfo->defs + j; if ((def->flags & QFOD_GLOBAL) @@ -623,6 +627,7 @@ linker_add_lib (const char *libname) } } while (did_something); pack_del (pack); + return 0; } qfo_t * diff --git a/tools/qfcc/source/obj_file.c b/tools/qfcc/source/obj_file.c index d4975f671..f819828f8 100644 --- a/tools/qfcc/source/obj_file.c +++ b/tools/qfcc/source/obj_file.c @@ -339,7 +339,6 @@ qfo_read (VFile *file) if (strcmp (hdr.qfo, QFO)) { fprintf (stderr, "not a qfo file\n"); - Qclose (file); return 0; } @@ -361,7 +360,6 @@ qfo_read (VFile *file) fprintf (stderr, "can't read version %x.%03x.%03x\n", (hdr.version >> 24) & 0xff, (hdr.version >> 12) & 0xfff, hdr.version & 0xfff); - Qclose (file); free (qfo); return 0; } @@ -374,7 +372,8 @@ qfo_read (VFile *file) qfo->relocs = malloc (qfo->num_relocs * sizeof (qfo_reloc_t)); qfo->defs = malloc (qfo->num_defs * sizeof (qfo_def_t)); qfo->funcs = malloc (qfo->num_funcs * sizeof (qfo_func_t)); - qfo->lines = malloc (qfo->num_lines * sizeof (pr_lineno_t)); + if (qfo->num_lines) + qfo->lines = malloc (qfo->num_lines * sizeof (pr_lineno_t)); qfo->types = malloc (qfo->types_size); Qread (file, qfo->code, qfo->code_size * sizeof (dstatement_t)); @@ -463,8 +462,10 @@ init_space (int size, pr_type_t *data) defspace_t *space = new_defspace (); space->size = size; space->max_size = RUP (space->size, 65536); + if (!space->max_size) + space->max_size=65536; + space->data = malloc (space->max_size * sizeof (pr_type_t)); if (size && data) { - space->data = malloc (space->max_size * sizeof (pr_type_t)); memcpy (space->data, data, size * sizeof (pr_type_t)); } return space; @@ -478,9 +479,10 @@ qfo_to_progs (qfo_t *qfo, pr_info_t *pr) qfo_func_t *qf; def_t *pd; qfo_def_t *qd; - reloc_t *relocs; + reloc_t *relocs = 0; - relocs = calloc (qfo->num_relocs, sizeof (reloc_t)); + if (qfo->num_relocs) + relocs = calloc (qfo->num_relocs, sizeof (reloc_t)); for (i = 0; i < qfo->num_relocs; i++) { if (i + 1 < qfo->num_relocs) relocs[i].next = &relocs[i + 1]; @@ -498,7 +500,8 @@ qfo_to_progs (qfo_t *qfo, pr_info_t *pr) pr->entity_data = new_defspace (); pr->scope = new_scope (sc_global, pr->near_data, 0); pr->scope->num_defs = qfo->num_defs; - pr->scope->head = calloc (pr->scope->num_defs, sizeof (def_t)); + if (qfo->num_defs) + pr->scope->head = calloc (pr->scope->num_defs, sizeof (def_t)); for (i = 0, pd = pr->scope->head, qd = qfo->defs; i < pr->scope->num_defs; i++, pd++, qd++) { *pr->scope->tail = pd; @@ -529,7 +532,8 @@ qfo_to_progs (qfo_t *qfo, pr_info_t *pr) } pr->num_functions = qfo->num_funcs + 1; - pr->func_head = calloc (qfo->num_funcs, sizeof (function_t)); + if (qfo->num_funcs) + pr->func_head = calloc (qfo->num_funcs, sizeof (function_t)); pr->func_tail = &pr->func_head; for (i = 0, pf = pr->func_head, qf = qfo->funcs; i < qfo->num_funcs; i++, pf++, qf++) { diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index d0dcb5b1e..eb9fd77cf 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -551,9 +551,11 @@ separate_compile (void) linker_begin (); for (file = source_files; *file; file++) { if (strncmp (*file, "-l", 2)) - linker_add_object_file (*file); + err = linker_add_object_file (*file); else - linker_add_lib (*file + 2); + err = linker_add_lib (*file + 2); + if (err) + return err; } qfo = linker_finish (); if (qfo) {