From 52010b8f7b969176e244c65c700f3d6d2793f160 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 14 Feb 2011 11:27:05 +0900 Subject: [PATCH] Do not segfault with bogus debug info. --- libs/gamecode/engine/pr_debug.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/gamecode/engine/pr_debug.c b/libs/gamecode/engine/pr_debug.c index 691e9e395..9c75870c5 100644 --- a/libs/gamecode/engine/pr_debug.c +++ b/libs/gamecode/engine/pr_debug.c @@ -386,8 +386,14 @@ PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno) if (lineno->line) return lineno->fa.addr; - f = &pr->auxfunctions[lineno->fa.func]; - return pr->pr_functions[f->function].first_statement; + if (lineno->fa.func >= 0 + && lineno->fa.func < pr->debug->num_auxfunctions) { + f = &pr->auxfunctions[lineno->fa.func]; + return pr->pr_functions[f->function].first_statement; + } + // take a wild guess that only the line number is bogus and return + // the address anyway + return lineno->fa.addr; } pr_uint_t @@ -423,6 +429,8 @@ PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno) pr_auxfunction_t *f; f = PR_Get_Lineno_Func (pr, lineno); + if (f->function >= (unsigned) pr->progs->numfunctions) + return 0; return PR_GetString(pr, pr->pr_functions[f->function].s_file); } @@ -447,7 +455,7 @@ PR_Get_Source_Line (progs_t *pr, pr_uint_t addr) file = PR_Load_Source_File (pr, fname); - if (!file || !file->lines || line > file->num_lines) + if (!file || !file->lines || !line || line > file->num_lines) return va ("%s:%u", fname, line); return va ("%s:%u:%.*s", fname, line, (int)file->lines[line - 1].len,