]> git.draconx.ca Git - cdecl99.git/commit
libcdecl: Fix parsing of very long specifier lists.
authorNick Bowler <nbowler@draconx.ca>
Thu, 11 Jan 2024 01:09:46 +0000 (20:09 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 11 Jan 2024 04:11:08 +0000 (23:11 -0500)
commita118e977106144aa753045c59e9f5278facc48d7
treedeaf81b7dfd83116eb71a4c500d4e32794cec782
parent4423b55b49e402ca3ac13a6430c23a6629da9bf4
libcdecl: Fix parsing of very long specifier lists.

Most of the current parser rules that deal with specifiers are arranged
such that all the relevant specifier symbols are shifted before any part
of the specifier list is reduced.  Thus, very long specifier lists (with
about 10000 or more specifiers) can lead to a parse error as the symbol
is exhausted (even if there would otherwise be enough memory to allocate
this many specifier items).

Since the C language allows certain specifiers to be repeated any number
of times, there are actually valid declarations with so many specifiers.

Simply collecting the specifiers in reverse order allows for the list
elements to be reduced as they are encountered, which avoids excessive
use of the symbol stack.  The order in which specifiers are parsed
does not matter and we can return these lists in any order.

Add a new test case to cover this behaviour.
src/parse.y
tests/stress.at