]> www.infradead.org Git - users/hch/misc.git/commit
genksyms: restrict direct-abstract-declarator to take one parameter-type-list
authorMasahiro Yamada <masahiroy@kernel.org>
Mon, 13 Jan 2025 15:00:45 +0000 (00:00 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 18 Jan 2025 00:11:46 +0000 (09:11 +0900)
commitc2f1846ba87ead7ac544be624c13249d6b90eca0
treec36134b82b39c5312101a7cf665aaa4f6088e4e5
parenta95298656c434357b38bec242412c65dcf6114d1
genksyms: restrict direct-abstract-declarator to take one parameter-type-list

While there is no more grammatical ambiguity in genksyms, the parser
logic is still inaccurate.

For example, genksyms accepts the following invalid C code:

    void my_func(int ()(int));

This should result in a syntax error because () cannot be reduced to
<direct-abstract-declarator>.

( <abstract-declarator> ) can be reduced, but <abstract-declarator>
must not be empty in the following grammar from K&R [1]:

  <direct-abstract-declarator> ::=  ( <abstract-declarator> )
                                 | {<direct-abstract-declarator>}? [ {<constant-expression>}? ]
                                 | {<direct-abstract-declarator>}? ( {<parameter-type-list>}? )

Furthermore, genksyms accepts the following weird code:

    void my_func(int (*callback)(int)(int)(int));

The parser allows <direct-abstract-declarator> to recursively absorb
multiple ( {<parameter-type-list>}? ), but this behavior is incorrect.

In the example above, (*callback) should be followed by at most one
(int).

[1]: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
scripts/genksyms/parse.y