From 1f6bc44b4854b13de2f428db8980c7f4546a8d25 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 5 Mar 2023 21:40:59 -0600 Subject: [PATCH] Fix handling of typedef names immediately after an inner scope where the identifier is redeclared. If an identifier is used as a typedef in an outer scope but then declared as something else in an inner scope (e.g. a variable name or tag), and that same identifier is the next token after the end of the inner scope, it would not be recognized properly as a typedef name leading to spurious errors.\ Here is an example that triggered this: typedef char Type; void f(int Type); Type t; Here is another one: int main(void) { typedef int S; if (1) (struct S {int a;} *)0; S x; } --- Symbol.pas | 9 ++++++++- cc.notes | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Symbol.pas b/Symbol.pas index c632dbb..8a506f1 100644 --- a/Symbol.pas +++ b/Symbol.pas @@ -2522,7 +2522,14 @@ if (lint & lintUnused) <> 0 then CheckUnused(tPtr); if tPtr^.next <> nil then begin table := table^.next; - if not tPtr^.isEmpty or (tablePoolSize = tablePoolMaxSize) then + if not tPtr^.isEmpty then begin + dispose(tPtr); + if token.kind = ident then + if FindSymbol(token,variableSpace,false,false) <> nil then + if token.symbolPtr^.class = typedefsy then + token.kind := typedef; + end {if} + else if (tablePoolSize = tablePoolMaxSize) then dispose(tPtr) else begin tPtr^.next := tablePool; diff --git a/cc.notes b/cc.notes index 697c609..448d27d 100644 --- a/cc.notes +++ b/cc.notes @@ -2142,6 +2142,8 @@ int foo(int[42]); 235. With certain inputs, the qsort() function could cause a stack overflow due to excessive recursion, potentially leading to crashes or other problems. Now its stack usage is limited to less than 600 bytes (usually significantly less), excluding whatever stack space may be used by the comparison function. +236. If a typedef name was used immediately after the end of an inner scope where the same name was used as a variable name or struct/union/enum tag, it might not be properly recognized as a typedef name, leading to spurious errors. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.