diff options
author | Peter Wu <peter@lekensteyn.nl> | 2017-03-29 19:24:37 +0200 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-03-29 20:11:07 +0000 |
commit | 483daa4d276968e152ac991323c9274c4cbf40ac (patch) | |
tree | d8c060882c6c326bfde5a14e4f4ee4000b4aaeab /tools/checkAPIs.pl | |
parent | 4d1060eca52e3ec39ca6da7e729b6bd63d71a063 (diff) |
checkAPIs.pl: check value_string termination
Check for the expected "{0, NULL}" termination, disallowing things like
"{9, NULL}". Also add val64_string and bytes_string while at it. Remove
a stale comment since we allow some c99 syntax now.
Change-Id: I1685255bbb11d84eba46b7cd00934d2f74187e03
Reviewed-on: https://code.wireshark.org/review/20792
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'tools/checkAPIs.pl')
-rwxr-xr-x | tools/checkAPIs.pl | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index 8801174df4..71842703ca 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -1434,7 +1434,8 @@ sub check_snprintf_plus_strlen($$) my $StaticRegex = qr/ static \s+ /xs; my $ConstRegex = qr/ const \s+ /xs; my $Static_andor_ConstRegex = qr/ (?: $StaticRegex $ConstRegex | $StaticRegex | $ConstRegex) /xs; -my $ValueStringRegex = qr/ ^ \s* $Static_andor_ConstRegex (?:value|string|range)_string \ + [^;*]+ = [^;]+ [{] .+? [}] \s*? ; /xms; +my $ValueStringVarnameRegex = qr/ (?:value|val64|string|range|bytes)_string /xs; +my $ValueStringRegex = qr/ ^ \s* $Static_andor_ConstRegex $ValueStringVarnameRegex \ + [^;*]+ = [^;]+ [{] .+? [}] \s*? ; /xms; my $EnumValRegex = qr/ $Static_andor_ConstRegex enum_val_t \ + [^;*]+ = [^;]+ [{] .+? [}] \s*? ; /xs; my $NewlineStringRegex = qr/ ["] [^"]* \\n [^"]* ["] /xs; @@ -1452,26 +1453,23 @@ sub check_value_string_arrays($$$) # XXX_string array definition found; check if NULL terminated my $vs = my $vsx = $1; if ($debug_flag) { - $vsx =~ / ( .+ (?:value|string|range)_string [^=]+ ) = /xo; + $vsx =~ / ( .+ $ValueStringVarnameRegex [^=]+ ) = /xo; printf STDERR "==> %-35.35s: %s\n", $filename, $1; printf STDERR "%s\n", $vs; } $vs =~ s{ \s } {}xg; - # README.developer says - # "Don't put a comma after the last tuple of an initializer of an array" - # However: since this usage is present in some number of cases, we'll allow for now - if ($vs !~ / , NULL [}] ,? [}] ; $/xo) { - $vsx =~ /( (?:value|string|range)_string [^=]+ ) = /xo; - printf STDERR "Error: %-35.35s: {..., NULL} is required as the last XXX_string array entry: %s\n", $filename, $1; + if ($vs !~ / (0|NULL), NULL [}] ,? [}] ; $/xo) { + $vsx =~ /( $ValueStringVarnameRegex [^=]+ ) = /xo; + printf STDERR "Error: %-35.35s: {0, NULL} is required as the last XXX_string array entry: %s\n", $filename, $1; $cnt++; } - if ($vs !~ / (static)? const (?:value|string|range)_string /xo) { - $vsx =~ /( (?:value|string|range)_string [^=]+ ) = /xo; + if ($vs !~ / (static)? const $ValueStringVarnameRegex /xo) { + $vsx =~ /( $ValueStringVarnameRegex [^=]+ ) = /xo; printf STDERR "Error: %-35.35s: Missing 'const': %s\n", $filename, $1; $cnt++; } - if ($vs =~ / $NewlineStringRegex /xo) { - $vsx =~ /( (?:value|string|range)_string [^=]+ ) = /xo; + if ($vs =~ / $NewlineStringRegex /xo && $vs !~ / bytes_string /xo) { + $vsx =~ /( $ValueStringVarnameRegex [^=]+ ) = /xo; printf STDERR "Error: %-35.35s: XXX_string contains a newline: %s\n", $filename, $1; $cnt++; } |