From 4d491a444d050cdded4e7a0ce44c7e093e918ebd Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 14 Feb 2022 14:28:19 +0900 Subject: [PATCH] [gamecode] Fix handling of undefined builtins The setup of the function descriptor for undefined builtins was incomplete and led to the progs running code at address 0. It didn't end well. --- include/QF/progs.h | 2 +- libs/gamecode/pr_builtins.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index 12d96f009..cd1008f91 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -1898,7 +1898,7 @@ struct progs_s { struct hashtab_s *builtin_hash; struct hashtab_s *builtin_num_hash; struct biblock_s *builtin_blocks; - pr_int_t bi_no_function; + builtin_t *bi_no_function; unsigned bi_next; unsigned (*bi_map) (progs_t *pr, unsigned binum); ///@} diff --git a/libs/gamecode/pr_builtins.c b/libs/gamecode/pr_builtins.c index cb0a5a694..821cc7d56 100644 --- a/libs/gamecode/pr_builtins.c +++ b/libs/gamecode/pr_builtins.c @@ -121,7 +121,7 @@ PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins, void *data) bi->name = "invalid function"; bi->proc = bi_no_function; bi->binum = builtin_next (pr); - pr->bi_no_function = bi->binum; + pr->bi_no_function = bi; DARRAY_APPEND (pr->builtin_blocks, bi); Hash_AddElement (pr->builtin_num_hash, bi); } @@ -212,9 +212,8 @@ PR_RelocateBuiltins (progs_t *pr) if (!bi) { Sys_Printf ("PR_RelocateBuiltins: %s: undefined builtin %s\n", pr->progs_name, bi_name); - desc->first_statement = -pr->bi_no_function; + bi = pr->bi_no_function; bad = 1; - continue; } desc->first_statement = -bi->binum; }