make qfo files typesize safe

This commit is contained in:
Bill Currie 2007-04-07 12:35:03 +00:00 committed by Jeff Teunissen
parent ce0e0d421e
commit 9509d0fd5e
4 changed files with 43 additions and 42 deletions

View file

@ -40,33 +40,33 @@
#define QFO_VERSION 0x00001005 // MMmmmRRR 0.001.005 (hex)
typedef struct qfo_header_s {
char qfo[4];
int version;
int code_size;
int data_size;
int far_data_size;
int strings_size;
int num_relocs;
int num_defs;
int num_funcs;
int num_lines;
int types_size;
int entity_fields;
int8_t qfo[4];
pr_int_t version;
pr_int_t code_size;
pr_int_t data_size;
pr_int_t far_data_size;
pr_int_t strings_size;
pr_int_t num_relocs;
pr_int_t num_defs;
pr_int_t num_funcs;
pr_int_t num_lines;
pr_int_t types_size;
pr_int_t entity_fields;
} qfo_header_t;
typedef struct qfo_def_s {
etype_t basic_type;
string_t full_type;
string_t name;
int ofs;
pr_int_t ofs;
int relocs;
int num_relocs;
pr_int_t relocs;
pr_int_t num_relocs;
unsigned flags;
pr_uint_t flags;
string_t file;
int line;
pr_int_t line;
} qfo_def_t;
#define QFOD_INITIALIZED (1u<<0)
@ -81,30 +81,30 @@ typedef struct qfo_def_s {
typedef struct qfo_func_s {
string_t name;
string_t file;
int line;
pr_int_t line;
int builtin;
int code;
pr_int_t builtin;
pr_int_t code;
int def;
pr_int_t def;
int locals_size;
int local_defs;
int num_local_defs;
pr_int_t locals_size;
pr_int_t local_defs;
pr_int_t num_local_defs;
int line_info;
pr_int_t line_info;
int num_parms;
pr_int_t num_parms;
byte parm_size[MAX_PARMS];
int relocs;
int num_relocs;
pr_int_t relocs;
pr_int_t num_relocs;
} qfo_func_t;
typedef struct qfo_reloc_s {
int ofs;
int type;
int def;
pr_int_t ofs;
pr_int_t type;
pr_int_t def;
} qfo_reloc_t;
typedef struct qfo_s {

View file

@ -131,7 +131,7 @@ emit_statement (expr_t *e, opcode_t *op, def_t *var_a, def_t *var_b,
abort ();
}
if (options.code.debug) {
unsigned int line = (e ? e->line : pr.source_line) - lineno_base;
pr_uint_t line = (e ? e->line : pr.source_line) - lineno_base;
if (line != pr.linenos[pr.num_linenos - 1].line) {
pr_lineno_t *lineno = new_lineno ();

View file

@ -347,7 +347,7 @@ process_field (qfo_def_t *def)
static void
fixup_def (qfo_t *qfo, qfo_def_t *def, int def_num)
{
int i;
pr_int_t i;
qfo_reloc_t *reloc;
qfo_func_t *func;
@ -553,7 +553,7 @@ move_def (hashtab_t *deftab, qfo_def_t *d)
defref_t *_d;
qfo_def_t *def;
int def_num = defs.num_defs;
int j;
pr_int_t j;
defgroup_add_defs (&defs, d, 1);
def = defs.defs + def_num;
@ -593,7 +593,8 @@ move_def (hashtab_t *deftab, qfo_def_t *d)
static void
merge_defgroups (void)
{
int local_base, i, j;
int local_base, i;
pr_int_t j;
qfo_def_t *def;
defref_t *d;
qfo_func_t *func;
@ -628,10 +629,10 @@ merge_defgroups (void)
}
for (i = 0; i < relocs.num_relocs; i = j) {
j = i;
while (j < relocs.num_relocs && relocs.relocs[j].type != rel_none)
// while (j < relocs.num_relocs && relocs.relocs[j].type != rel_none)
j++;
relocgroup_add_relocs (&final_relocs, relocs.relocs + i, j - i);
while (j < relocs.num_relocs && relocs.relocs[j].type == rel_none)
// while (j < relocs.num_relocs && relocs.relocs[j].type == rel_none)
j++;
}
}
@ -817,7 +818,7 @@ static void
undefined_def (qfo_def_t *def)
{
qfo_def_t line_def;
int i;
pr_int_t i;
qfo_reloc_t *reloc = relocs.relocs + def->relocs;
for (i = 0; i < def->num_relocs; i++, reloc++) {
@ -830,7 +831,7 @@ undefined_def (qfo_def_t *def)
&& lines.lines) {
qfo_func_t *func = funcs.funcs;
qfo_func_t *best = func;
int best_dist = reloc->ofs - func->code;
pr_int_t best_dist = reloc->ofs - func->code;
pr_lineno_t *line;
while (best_dist && func - funcs.funcs < funcs.num_funcs) {
@ -846,9 +847,9 @@ undefined_def (qfo_def_t *def)
line_def.file = best->file;
line_def.line = best->line;
if (!line->line
&& line->fa.func == (unsigned) (best - funcs.funcs)) {
&& line->fa.func == (pr_uint_t) (best - funcs.funcs)) {
while (line - lines.lines < lines.num_lines - 1 && line[1].line
&& line[1].fa.addr <= (unsigned) reloc->ofs)
&& line[1].fa.addr <= (pr_uint_t) reloc->ofs)
line++;
line_def.line = line->line + best->line;
}

View file

@ -349,7 +349,7 @@ qfo_read (QFile *file)
Qread (file, &hdr, sizeof (hdr));
if (strcmp (hdr.qfo, QFO)) {
if (memcmp (hdr.qfo, QFO, 4)) {
fprintf (stderr, "not a qfo file\n");
return 0;
}