]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Fix parsing of very long declarator lists.
authorNick Bowler <nbowler@draconx.ca>
Thu, 11 Jan 2024 03:28:01 +0000 (22:28 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 11 Jan 2024 04:12:38 +0000 (23:12 -0500)
The way the toplevel declaration parser is currently arranged requires
shifting every declarator symbol before any part of the full declarator
list is reduced.  Thus, very long declarations (with about 5000 or more
full declarators) can lead to a parse error since the symbol stack is
exhausted (even if there would otherwise be enough memory to allocate
this many declarator items).

Technically this kind of failure is permitted by the C language, as
implementations are not required to support declarations of this size.
However, it is better to avoid arbitrary limits like this and it is not
a big problem to do so.

Simply collecting the declarators in reverse order allows for the list
elements to be reduced as they are encountered, which avoids excessive
use of the symbol stack.  However in this case the order matters, so
the final list must be reversed before it is returned from the parser.

Add a new test case to cover this behaviour.


No differences found