Skip to content

Commit d2d154b

Browse files
committed
ParseXS: fix handling of empty C_ARGS etc
GH#23407 My recent refactoring work on ParseXS made the parser go into an infinite loop on multiline_merged nodes such as C_ARGS when there was no text, e.g. void foo(int a) C_ARGS:
1 parent b0823b6 commit d2d154b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3648,7 +3648,7 @@ sub parse {
36483648
$self->SUPER::parse($pxs); # set file/line_no, read lines
36493649

36503650
my @lines = @{$self->{lines}};
3651-
shift @lines while $lines[0] !~ /\S/;
3651+
shift @lines while @lines && $lines[0] !~ /\S/;
36523652
# XXX ParseXS originally didn't include a trailing \n,
36533653
# so we carry on doing the same.
36543654
$self->{text} = join "\n", @lines;

dist/ExtUtils-ParseXS/t/001-basic.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,16 @@ EOF
16561656
[ 0, 0, qr/\Qfoo(a, b , bar, c? c : "boo!")/, "" ],
16571657
],
16581658
1659+
[
1660+
"autocall args empty C_ARGS",
1661+
[ Q(<<'EOF') ],
1662+
|void
1663+
|foo(int a)
1664+
| C_ARGS:
1665+
EOF
1666+
[ 0, 0, qr/\Qfoo()/, "" ],
1667+
],
1668+
16591669
[
16601670
# Whether this is sensible or not is another matter.
16611671
# For now, just check that it works as-is.

0 commit comments

Comments
 (0)