]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: fix regexp for ASSIGNWITHINCONDITION
authorDaniel Gustafsson <daniel@yesql.se>
Thu, 28 Nov 2019 13:16:02 +0000 (14:16 +0100)
committerDaniel Gustafsson <daniel@yesql.se>
Thu, 28 Nov 2019 13:18:16 +0000 (14:18 +0100)
The regexp looking for assignments within conditions was too greedy
and matched a too long string in the case of multiple conditionals
on the same line. This is basically only a problem in single line
macros, and the code which exemplified this was essentially:

  do { if((x) != NULL) { x = NULL; } } while(0)

..where the final parenthesis of while(0) matched the regexp, and
the legal assignment in the block triggered the warning. Fix by
making the regexp less greedy by matching for the tell-tale signs
of the if statement ending.

Also remove the one occurrence where the warning was disabled due
to a construction like the above, where the warning didn't apply
when fixed.

Closes #4647
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
lib/checksrc.pl
lib/vssh/libssh.c

index 8343645610003f55936128cc7c455c8add9b736e..db9a45dff39950decc80e5ecaf94662a69191aa8 100755 (executable)
@@ -457,7 +457,7 @@ sub scanfile {
             }
         }
 
-        if($nostr =~ /^((.*)(if) *\()(.*)\)/) {
+        if($nostr =~ /^((.*)(if) *\()(.*)\) [{\n]/) {
             my $pos = length($1);
             if($4 =~ / = /) {
                 checkwarn("ASSIGNWITHINCONDITION",
index cad8b378642a52994c282fd86f56a5d97562e413..070879d94631b9e824ac55c9a28ca0c839e0e605 100644 (file)
@@ -97,7 +97,6 @@
 
 /* A recent macro provided by libssh. Or make our own. */
 #ifndef SSH_STRING_FREE_CHAR
-/* !checksrc! disable ASSIGNWITHINCONDITION 1 */
 #define SSH_STRING_FREE_CHAR(x) \
     do { if((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
 #endif