From 63d33b47bf88850417eed31981b7c5e90aaefb2b Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 12 Jul 2022 18:34:58 -0500 Subject: [PATCH] Generate valid code for "dereferencing" pointers to void. This covers code like the following, which is very dubious but does not seem to be clearly prohibited by the standards: int main(void) { void *vp; *vp; } Previously, this would do an indirect load of a four-byte value at the location, but then treat it as void. This could lead to the four-byte value being left on the stack, eventually causing a crash. Now we just evaluate the pointer expression (in case it has side effects), but effectively cast it to void without dereferencing it. --- Expression.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Expression.pas b/Expression.pas index 986ad7a..0143053 100644 --- a/Expression.pas +++ b/Expression.pas @@ -4564,7 +4564,7 @@ case tree^.token.kind of isVolatile := tqVolatile in lType^.qualifiers; if lType^.kind = scalarType then if lType^.baseType = cgVoid then - Gen2t(pc_ind, ord(isVolatile), 0, cgULong) + Gen2(pc_cnv, cgULong, cgVoid) else Gen2t(pc_ind, ord(isVolatile), 0, lType^.baseType) else if lType^.kind = pointerType then