]> git.draconx.ca Git - cdecl99.git/commit
libcdecl: Fix parsing of very long parameter lists.
authorNick Bowler <nbowler@draconx.ca>
Thu, 11 Jan 2024 04:08:14 +0000 (23:08 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 11 Jan 2024 06:49:41 +0000 (01:49 -0500)
commita41aa156f28753613f38924fc856d3dc992cfc56
tree10f1948a1788222e072bdb5b78bed287d2b606da
parenta2c3dad92b2bf55488174c203563224880380c9b
libcdecl: Fix parsing of very long parameter lists.

The way the parameter parser rules are currently arranged requires
shifting every parameter symbol before any part of the parameter
list is reduced.  Thus, functions with a lot of parameters (about
5000 or more) can lead to a parse error since the symbol stack is
exhausted (even if there would otherwise be enough memory to
allocate this many parameter items).

Technically this kind of failure is permitted by the C language, as
implementations do not need to support functions with more than 127
parameters.  However, it is better to avoid arbitrary limits like
this and it is not a big problem to do so.

Collecting the parameters in reverse order allows the list elements
to be reduced as they are encountered, which avoids excessive use
of the symbol stack.  The final list has to then be reversed again
prior to returning from the parser.  This is actually how the prior
release 1.2 worked so this is technically a regression fix.

Expand some test cases to cover this behaviour.  We actually don't
have any tests targeting the parameter ordering (although randomdecl
and crossparse quickly catches it) so add some of those too.
src/parse.y
tests/decl-good.at
tests/stress.at