From 6df79b2b06932a12c7f6a38396cc251ba31eb87e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 18 Jan 2022 21:42:53 +0900 Subject: [PATCH] [qfcc] Correct xdef structures and usage in test Attempting to add ev_ushort caused ptraliasenc to break, but that was because it was already broken: I had implemented the scan of the xdef table incorrectly, thus adding only 1 ev type resulted in the walked pointer being out of phase with its data due to it first passing over the type encodings (which is why adding long and ulong didn't cause any obvious trouble). --- tools/qfcc/source/type.c | 4 ++-- tools/qfcc/test/ptraliasenc.r | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index c29c910bc..1e03bf19d 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -1210,7 +1210,7 @@ init_types (void) }; static struct_def_t type_encoding_struct[] = { {"types", &type_pointer}, - {"size", &type_int}, + {"size", &type_uint}, {0, 0} }; static struct_def_t xdef_struct[] = { @@ -1220,7 +1220,7 @@ init_types (void) }; static struct_def_t xdefs_struct[] = { {"xdefs", &type_xdef_pointer}, - {"num_xdefs", &type_pointer}, + {"num_xdefs", &type_uint}, {0, 0} }; static struct_def_t va_list_struct[] = { diff --git a/tools/qfcc/test/ptraliasenc.r b/tools/qfcc/test/ptraliasenc.r index 2f305617f..8e8a58e9c 100644 --- a/tools/qfcc/test/ptraliasenc.r +++ b/tools/qfcc/test/ptraliasenc.r @@ -10,16 +10,22 @@ typedef struct xdef_s { void *ofs; ///< 32-bit version of ddef_t.ofs } xdef_t; +typedef struct xdefs_s { + xdef_t *xdefs; + unsigned num_xdefs; +} xdefs_t; + void *PR_FindGlobal (string name) = #0; int main (void) { //FIXME need a simple way to get at a def's meta-data - xdef_t *xdefs = PR_FindGlobal (".xdefs"); - while (xdefs.ofs != &int32_ptr) { - xdefs++; + xdefs_t *xdefs = PR_FindGlobal (".xdefs"); + xdef_t *xdef = xdefs.xdefs; + while (xdef - xdefs.xdefs < xdefs.num_xdefs && xdef.ofs != &int32_ptr) { + xdef++; } - printf ("int32_ptr: %s\n", xdefs.type.encoding); - return xdefs.type.encoding != "{>^i}"; + printf ("int32_ptr: %s\n", xdef.type.encoding); + return xdef.type.encoding != "{>^i}"; }