1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-10 11:35:07 -05:00

checksrc: fix regexp for ASSIGNWITHINCONDITION

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>
This commit is contained in:
Daniel Gustafsson 2019-11-28 14:16:02 +01:00
parent a956a8c5b4
commit ba82673dac
2 changed files with 1 additions and 2 deletions

View File

@ -457,7 +457,7 @@ sub scanfile {
} }
} }
if($nostr =~ /^((.*)(if) *\()(.*)\)/) { if($nostr =~ /^((.*)(if) *\()(.*)\) [{\n]/) {
my $pos = length($1); my $pos = length($1);
if($4 =~ / = /) { if($4 =~ / = /) {
checkwarn("ASSIGNWITHINCONDITION", checkwarn("ASSIGNWITHINCONDITION",

View File

@ -97,7 +97,6 @@
/* A recent macro provided by libssh. Or make our own. */ /* A recent macro provided by libssh. Or make our own. */
#ifndef SSH_STRING_FREE_CHAR #ifndef SSH_STRING_FREE_CHAR
/* !checksrc! disable ASSIGNWITHINCONDITION 1 */
#define SSH_STRING_FREE_CHAR(x) \ #define SSH_STRING_FREE_CHAR(x) \
do { if((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0) do { if((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
#endif #endif