]> git.draconx.ca Git - cdecl99.git/commit
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)
commita2c3dad92b2bf55488174c203563224880380c9b
tree6703e391d56e18b25ec3a8c2f37c2ae6527bb292
parenta118e977106144aa753045c59e9f5278facc48d7
libcdecl: Fix parsing of very long declarator lists.

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.
src/parse.y
tests/stress.at