Add some safety checks to progs global dumping.

Getting segfaults in the debug tools is not fun :P

Conflicts:
	tools/qfcc/source/dump_globals.c
This commit is contained in:
Bill Currie 2012-11-03 18:14:21 +09:00
parent cc24e2e67e
commit 7a2f7e8982

View file

@ -63,8 +63,10 @@ dump_def (progs_t *pr, ddef_t *def, int indent)
{
const char *name;
const char *type;
int offset;
pr_uint_t offset;
const char *comment;
string_t string;
const char *str;
int saveglobal;
if (!def->type && !def->ofs && !def->s_name)
@ -75,14 +77,21 @@ dump_def (progs_t *pr, ddef_t *def, int indent)
saveglobal = (def->type & DEF_SAVEGLOBAL) != 0;
offset = def->ofs;
comment = "";
comment = " invalid offset";
if (offset < pr->progs->numglobals) {
switch (def->type & ~DEF_SAVEGLOBAL) {
case ev_void:
break;
case ev_string:
comment = va (" %d \"%s\"", G_INT (pr, offset),
quote_string (pr->pr_strings + G_INT (pr, offset)));
string = G_INT (pr, offset);
if (string < 0 || string >= pr->progs->numstrings) {
str = "invalid string offset";
comment = va (" %d %s", string, str);
} else {
str = quote_string (pr->pr_strings + G_INT (pr, offset));
comment = va (" %d \"%s\"", string, str);
}
break;
case ev_float:
comment = va (" %g", G_FLOAT (pr, offset));
@ -134,6 +143,7 @@ dump_def (progs_t *pr, ddef_t *def, int indent)
case ev_type_count:
break;
}
}
printf ("%*s %x %d %s %s%s\n", indent * 12, "",
offset, saveglobal, name, type, comment);
}