This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix for [perl #32491] h2xs incorrectly parses enums with implicit values
[perl5.git] / utils / h2xs.PL
index ceac64e..b973705 100644 (file)
@@ -901,8 +901,8 @@ if( @path_h ){
             next if $opt_e && $enum_name =~ /$opt_e/;
             my $val = 0;
             for my $item (split /,/, $enum_body) {
-                my ($key, $declared_val) = $item =~ /(\w+)\s*=\s*(.*)/;
-                $val = length($declared_val) ? $declared_val : 1 + $val;
+                my ($key, $declared_val) = $item =~ /(\w+)\s*(?:=\s*(.*))?/;
+                $val = defined($declared_val) && length($declared_val) ? $declared_val : 1 + $val;
                 $seen_define{$key} = $declared_val;
                 $const_names{$key}++;
             }