summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-10-16 13:50:25 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-10-17 11:19:49 +0200
commit53418dbc847c9a78d79ee81b702770a0efe9cf22 (patch)
treee8e518597e3ec3466eb98dbd15a84b410dc17017 /lib
parentefffa66f655c04747e14cd734fce7fcb9626c413 (diff)
downloadcurl-53418dbc847c9a78d79ee81b702770a0efe9cf22.tar.gz
checksrc: ignore preprocessor lines
In order to check the actual code better, checksrc now ignores everything that look like preprocessor instructions. It also means that code in macros are now longer checked. Note that some rules then still don't need to be followed when code is exactly below a cpp instruction. Removes two checksrc exceptions we needed previously because of preprocessor lines being checked. Reported-by: Marcel Raad Fixes #7863 Closes #7864
Diffstat (limited to 'lib')
-rwxr-xr-xlib/checksrc.pl37
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/checksrc.pl b/lib/checksrc.pl
index ac7e3847e..bb3495f79 100755
--- a/lib/checksrc.pl
+++ b/lib/checksrc.pl
@@ -370,7 +370,10 @@ sub scanfile {
my $line = 1;
my $prevl="";
- my $l;
+ my $prevpl="";
+ my $l = "";
+ my $prep = 0;
+ my $prevp = 0;
open(R, "<$file") || die "failed to open $file";
my $incomment=0;
@@ -452,6 +455,14 @@ sub scanfile {
# comments
# ------------------------------------------------------------
+ # prev line was a preprocessor **and** ended with a backslash
+ if($prep && ($prevpl =~ /\\ *\z/)) {
+ # this is still a preprocessor line
+ $prep = 1;
+ goto preproc;
+ }
+ $prep = 0;
+
# crude attempt to detect // comments without too many false
# positives
if($l =~ /^(([^"\*]*)[^:"]|)\/\//) {
@@ -459,6 +470,13 @@ sub scanfile {
$line, length($1), $file, $l, "\/\/ comment");
}
+ # detect and strip preprocessor directives
+ if($l =~ /^[ \t]*\#/) {
+ # preprocessor line
+ $prep = 1;
+ goto preproc;
+ }
+
my $nostr = nostrings($l);
# check spaces after for/if/while/function call
if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) {
@@ -676,10 +694,9 @@ sub scanfile {
}
}
- # check for open brace first on line but not first column
- # only alert if previous line ended with a close paren and wasn't a cpp
- # line
- if((($prevl =~ /\)\z/) && ($prevl !~ /^ *#/)) && ($l =~ /^( +)\{/)) {
+ # check for open brace first on line but not first column only alert
+ # if previous line ended with a close paren and it wasn't a cpp line
+ if(($prevl =~ /\)\z/) && ($l =~ /^( +)\{/) && !$prevp) {
checkwarn("BRACEPOS",
$line, length($1), $file, $ol, "badly placed open brace");
}
@@ -687,11 +704,11 @@ sub scanfile {
# if the previous line starts with if/while/for AND ends with an open
# brace, or an else statement, check that this line is indented $indent
# more steps, if not a cpp line
- if($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/) {
+ if(!$prevp && ($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/)) {
my $first = length($1);
# this line has some character besides spaces
- if(($l !~ /^ *#/) && ($l =~ /^( *)[^ ]/)) {
+ if($l =~ /^( *)[^ ]/) {
my $second = length($1);
my $expect = $first+$indent;
if($expect != $second) {
@@ -786,9 +803,11 @@ sub scanfile {
print STDERR "L: $l\n";
print STDERR "nostr: $nostr\n";
}
-
+ preproc:
$line++;
- $prevl = $ol;
+ $prevp = $prep;
+ $prevl = $ol if(!$prep);
+ $prevpl = $ol if($prep);
}
if(!scalar(@copyright)) {