mirror of
https://github.com/curl/curl.git
synced 2026-07-25 23:07:16 +03:00
checksrc: fix SPACEBEFOREPAREN for conditions starting with "*"
The open paren check wants to warn for spaces before open parenthesis for if/while/for but also for any function call. In order to avoid catching function pointer declarations, the logic allows a space if the first character after the open parenthesis is an asterisk. I also spotted what we did not include "switch" in the check but we should. This check is a little lame, but we reduce this problem by not allowing that space for if/while/for/switch. Reported-by: Emanuele Torre Closes #11044
This commit is contained in:
parent
4578ada4a0
commit
d567cca1de
14 changed files with 22 additions and 20 deletions
|
|
@ -517,7 +517,8 @@ sub scanfile {
|
|||
|
||||
my $nostr = nostrings($l);
|
||||
# check spaces after for/if/while/function call
|
||||
if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) {
|
||||
if($nostr =~ /^(.*)(for|if|while|switch| ([a-zA-Z0-9_]+)) \((.)/) {
|
||||
my ($leading, $word, $extra, $first)=($1,$2,$3,$4);
|
||||
if($1 =~ / *\#/) {
|
||||
# this is a #if, treat it differently
|
||||
}
|
||||
|
|
@ -527,15 +528,16 @@ sub scanfile {
|
|||
elsif(defined $3 && $3 eq "case") {
|
||||
# case must have a space
|
||||
}
|
||||
elsif($4 eq "*") {
|
||||
# (* beginning makes the space OK!
|
||||
elsif(($first eq "*") && ($word !~ /(for|if|while|switch)/)) {
|
||||
# A "(*" beginning makes the space OK because it wants to
|
||||
# allow funcion pointer declared
|
||||
}
|
||||
elsif($1 =~ / *typedef/) {
|
||||
# typedefs can use space-paren
|
||||
}
|
||||
else {
|
||||
checkwarn("SPACEBEFOREPAREN", $line, length($1)+length($2), $file, $l,
|
||||
"$2 with space");
|
||||
checkwarn("SPACEBEFOREPAREN", $line, length($leading)+length($word), $file, $l,
|
||||
"$word with space");
|
||||
}
|
||||
}
|
||||
# check for '== NULL' in if/while conditions but not if the thing on
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue