diff options
author | Peter Wu <peter@lekensteyn.nl> | 2017-03-30 13:26:56 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2017-03-31 09:17:42 +0000 |
commit | 641a48ec68778a5eaed82e436c09642e9ef1f911 (patch) | |
tree | 9b97002cd118761f444fa077632d34a084b081ba /tools | |
parent | 08963526bc618cb827f7e1eddb547c3bea0d2017 (diff) | |
download | wireshark-641a48ec68778a5eaed82e436c09642e9ef1f911.tar.gz |
checkAPIs: improve trailing item suggestion for XXX_string
Tighten the check (do not just check for "0,NULL}};" but also
"{0,NULL}};" in case someone decides to use "{0x10,NULL}};" as trailing
item. Improve the suggestion, "{NULL,NULL}" is better for string_string
than "{0,NULL}".
For now treat 0 the same as NULL since files like packet-fix.h would
need editing otherwise. Accept octal notation for value_string since
packet-nfs.c uses this in nfs2_mode_names.
Change-Id: Ic507dbd8b07f3ae062b3f0310aa3398115d54273
Reviewed-on: https://code.wireshark.org/review/20796
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/checkAPIs.pl | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index 71842703ca..7ea8a1d0d4 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -1435,7 +1435,7 @@ my $StaticRegex = qr/ static \s+ my $ConstRegex = qr/ const \s+ /xs; my $Static_andor_ConstRegex = qr/ (?: $StaticRegex $ConstRegex | $StaticRegex | $ConstRegex) /xs; my $ValueStringVarnameRegex = qr/ (?:value|val64|string|range|bytes)_string /xs; -my $ValueStringRegex = qr/ ^ \s* $Static_andor_ConstRegex $ValueStringVarnameRegex \ + [^;*]+ = [^;]+ [{] .+? [}] \s*? ; /xms; +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,23 +1452,44 @@ sub check_value_string_arrays($$$) while (${$fileContentsRef} =~ / ( $ValueStringRegex ) /xsog) { # XXX_string array definition found; check if NULL terminated my $vs = my $vsx = $1; + my $type = $2; if ($debug_flag) { $vsx =~ / ( .+ $ValueStringVarnameRegex [^=]+ ) = /xo; printf STDERR "==> %-35.35s: %s\n", $filename, $1; printf STDERR "%s\n", $vs; } $vs =~ s{ \s } {}xg; - if ($vs !~ / (0|NULL), NULL [}] ,? [}] ; $/xo) { + + # Check for expected trailer + my $expectedTrailer; + my $trailerHint; + if ($type eq "string_string") { + # XXX shouldn't we reject 0 since it is gchar*? + $expectedTrailer = "(NULL|0), NULL"; + $trailerHint = "NULL, NULL"; + } elsif ($type eq "range_string") { + $expectedTrailer = "0(x0+)?, 0(x0+)?, NULL"; + $trailerHint = "0, 0, NULL"; + } elsif ($type eq "bytes_string") { + # XXX shouldn't we reject 0 since it is guint8*? + $expectedTrailer = "(NULL|0), 0, NULL"; + $trailerHint = "NULL, NULL"; + } else { + $expectedTrailer = "0(x?0+)?, NULL"; + $trailerHint = "0, NULL"; + } + if ($vs !~ / [{] $expectedTrailer [}] ,? [}] ; $/x) { $vsx =~ /( $ValueStringVarnameRegex [^=]+ ) = /xo; - printf STDERR "Error: %-35.35s: {0, NULL} is required as the last XXX_string array entry: %s\n", $filename, $1; + printf STDERR "Error: %-35.35s: {%s} is required as the last %s array entry: %s\n", $filename, $trailerHint, $type, $1; $cnt++; } + 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 && $vs !~ / bytes_string /xo) { + if ($vs =~ / $NewlineStringRegex /xo && $type ne "bytes_string") { $vsx =~ /( $ValueStringVarnameRegex [^=]+ ) = /xo; printf STDERR "Error: %-35.35s: XXX_string contains a newline: %s\n", $filename, $1; $cnt++; |