Skip to content

Commit 1117b67

Browse files
committed
checksrc: update, check all sources, fix fallouts
update from curl: https://github.com/curl/curl/blob/cff75acfeca65738da8297aee0b30427b004b240/scripts/checksrc.pl Closes libssh2#1457
1 parent d9c2e55 commit 1117b67

21 files changed

+632
-478
lines changed

Diff for: .checksrc

-3
This file was deleted.

Diff for: Makefile.am

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,4 @@ gen-coverage:
8181
coverage: init-coverage build-coverage gen-coverage
8282

8383
checksrc:
84-
perl ci/checksrc.pl -i4 -m79 \
85-
-Wsrc/libssh2_config.h \
86-
src/*.[ch] include/*.h example/*.c tests/*.[ch]
84+
ci/checksrc.sh

Diff for: REUSE.toml

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ path = [
4444
"vms/man2help.c",
4545
"vms/readme.vms",
4646
# dotfiles
47-
".checksrc",
4847
".editorconfig",
4948
".gitignore",
5049
"docs/.gitignore",

Diff for: ci/checksrc.pl

+139-47
Original file line numberDiff line numberDiff line change
@@ -50,54 +50,58 @@
5050
my %warnings_extended = (
5151
'COPYRIGHTYEAR' => 'copyright year incorrect',
5252
'STRERROR', => 'strerror() detected',
53+
'STRNCPY', => 'strncpy() detected',
5354
'STDERR', => 'stderr detected',
5455
);
5556

5657
my %warnings = (
5758
'ASSIGNWITHINCONDITION' => 'assignment within conditional expression',
58-
'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
59-
'ASTERISKSPACE' => 'pointer declared with space after asterisk',
60-
'BADCOMMAND' => 'bad !checksrc! instruction',
61-
'BANNEDFUNC' => 'a banned function was used',
62-
'BANNEDPREPROC' => 'a banned symbol was used on a preprocessor line',
63-
'BRACEELSE' => '} else on the same line',
64-
'BRACEPOS' => 'wrong position for an open brace',
65-
'BRACEWHILE' => 'A single space between open brace and while',
66-
'COMMANOSPACE' => 'comma without following space',
67-
'COMMENTNOSPACEEND' => 'no space before */',
68-
'COMMENTNOSPACESTART' => 'no space following /*',
69-
'COPYRIGHT' => 'file missing a copyright statement',
70-
'CPPCOMMENTS' => '// comment detected',
71-
'DOBRACE' => 'A single space between do and open brace',
72-
'EMPTYLINEBRACE' => 'Empty line before the open brace',
73-
'EQUALSNOSPACE' => 'equals sign without following space',
74-
'EQUALSNULL' => 'if/while comparison with == NULL',
75-
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
76-
'FOPENMODE' => 'fopen needs a macro for the mode string',
77-
'INCLUDEDUP', => 'same file is included again',
78-
'INDENTATION' => 'wrong start column for code',
79-
'LONGLINE' => "Line longer than $max_column",
80-
'SPACEBEFORELABEL' => 'labels not at the start of the line',
81-
'MULTISPACE' => 'multiple spaces used when not suitable',
82-
'NOSPACEEQUALS' => 'equals sign without preceding space',
83-
'NOTEQUALSZERO', => 'if/while comparison with != 0',
84-
'ONELINECONDITION' => 'conditional block on the same line as the if()',
85-
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
86-
'PARENBRACE' => '){ without sufficient space',
87-
'RETURNNOSPACE' => 'return without space',
88-
'SEMINOSPACE' => 'semicolon without following space',
89-
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
90-
'SNPRINTF' => 'use of snprintf',
91-
'SPACEAFTERPAREN' => 'space after open parenthesis',
92-
'SPACEBEFORECLOSE' => 'space before a close parenthesis',
93-
'SPACEBEFORECOMMA' => 'space before a comma',
94-
'SPACEBEFOREPAREN' => 'space before an open parenthesis',
95-
'SPACESEMICOLON' => 'space before semicolon',
96-
'SPACESWITCHCOLON' => 'space before colon of switch label',
97-
'TABS' => 'TAB characters not allowed',
98-
'TRAILINGSPACE' => 'Trailing whitespace on the line',
99-
'TYPEDEFSTRUCT' => 'typedefed struct',
100-
'UNUSEDIGNORE' => 'a warning ignore was not used',
59+
'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
60+
'ASTERISKSPACE' => 'pointer declared with space after asterisk',
61+
'BADCOMMAND' => 'bad !checksrc! instruction',
62+
'BANNEDFUNC' => 'a banned function was used',
63+
'BANNEDPREPROC' => 'a banned symbol was used on a preprocessor line',
64+
'BRACEELSE' => '} else on the same line',
65+
'BRACEPOS' => 'wrong position for an open brace',
66+
'BRACEWHILE' => 'A single space between open brace and while',
67+
'COMMANOSPACE' => 'comma without following space',
68+
'COMMENTNOSPACEEND' => 'no space before */',
69+
'COMMENTNOSPACESTART' => 'no space following /*',
70+
'COPYRIGHT' => 'file missing a copyright statement',
71+
'CPPCOMMENTS' => '// comment detected',
72+
'DOBRACE' => 'A single space between do and open brace',
73+
'EMPTYLINEBRACE' => 'Empty line before the open brace',
74+
'EQUALSNOSPACE' => 'equals sign without following space',
75+
'EQUALSNULL' => 'if/while comparison with == NULL',
76+
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
77+
'FOPENMODE' => 'fopen needs a macro for the mode string',
78+
'INCLUDEDUP', => 'same file is included again',
79+
'INDENTATION' => 'wrong start column for code',
80+
'LONGLINE' => "Line longer than $max_column",
81+
'SPACEBEFORELABEL' => 'labels not at the start of the line',
82+
'MULTISPACE' => 'multiple spaces used when not suitable',
83+
'NOSPACEC' => 'missing space around ternary colon operator',
84+
'NOSPACEEQUALS' => 'equals sign without preceding space',
85+
'NOSPACEQ' => 'missing space around ternary question mark operator',
86+
'NOSPACETHAN' => 'missing space around less or greater than',
87+
'NOTEQUALSZERO', => 'if/while comparison with != 0',
88+
'ONELINECONDITION' => 'conditional block on the same line as the if()',
89+
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
90+
'PARENBRACE' => '){ without sufficient space',
91+
'RETURNNOSPACE' => 'return without space',
92+
'SEMINOSPACE' => 'semicolon without following space',
93+
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
94+
'SNPRINTF' => 'use of snprintf',
95+
'SPACEAFTERPAREN' => 'space after open parenthesis',
96+
'SPACEBEFORECLOSE' => 'space before a close parenthesis',
97+
'SPACEBEFORECOMMA' => 'space before a comma',
98+
'SPACEBEFOREPAREN' => 'space before an open parenthesis',
99+
'SPACESEMICOLON' => 'space before semicolon',
100+
'SPACESWITCHCOLON' => 'space before colon of switch label',
101+
'TABS' => 'TAB characters not allowed',
102+
'TRAILINGSPACE' => 'Trailing whitespace on the line',
103+
'TYPEDEFSTRUCT' => 'typedefed struct',
104+
'UNUSEDIGNORE' => 'a warning ignore was not used',
101105
);
102106

103107
sub readskiplist {
@@ -115,11 +119,23 @@ sub readskiplist {
115119
# and since that's already handled via !checksrc! commands there is probably
116120
# little use to add it.
117121
sub readlocalfile {
122+
my ($file) = @_;
118123
my $i = 0;
124+
my $rcfile;
119125

120-
open(my $rcfile, "<", "$dir/.checksrc") or return;
126+
if(($dir eq ".") && $file =~ /\//) {
127+
my $ldir;
128+
if($file =~ /(.*)\//) {
129+
$ldir = $1;
130+
open($rcfile, "<", "$dir/$ldir/.checksrc") or return;
131+
}
132+
}
133+
else {
134+
open($rcfile, "<", "$dir/.checksrc") or return;
135+
}
121136

122137
while(<$rcfile>) {
138+
$windows_os ? $_ =~ s/\r?\n$// : chomp;
123139
$i++;
124140

125141
# Lines starting with '#' are considered comments
@@ -263,7 +279,7 @@ sub checkwarn {
263279
}
264280

265281
readskiplist();
266-
readlocalfile();
282+
readlocalfile($file);
267283

268284
do {
269285
if("$wlist" !~ / $file /) {
@@ -403,6 +419,13 @@ sub scanfile {
403419
checksrc($cmd, $line, $file, $l)
404420
}
405421

422+
if($l =~ /^#line (\d+) \"([^\"]*)\"/) {
423+
# a #line instruction
424+
$file = $2;
425+
$line = $1;
426+
next;
427+
}
428+
406429
# check for a copyright statement and save the years
407430
if($l =~ /\* +copyright .* (\d\d\d\d|)/i) {
408431
my $count = 0;
@@ -603,6 +626,62 @@ sub scanfile {
603626
"space after open parenthesis");
604627
}
605628

629+
# check spaces before colon
630+
if($nostr =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
631+
my $m = $1;
632+
my $e = $nostr;
633+
$e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that surround colon
634+
$e =~ s/':'//g; # ignore these
635+
if($e =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
636+
checkwarn("NOSPACEC",
637+
$line, length($m)+1, $file, $l,
638+
"missing space before colon");
639+
}
640+
}
641+
# check spaces after colon
642+
if($nostr =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
643+
my $m = $1;
644+
my $e = $nostr;
645+
$e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that surround colon
646+
$e =~ s/':'//g; # ignore these
647+
if($e =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
648+
checkwarn("NOSPACEC",
649+
$line, length($m)+1, $file, $l,
650+
"missing space after colon");
651+
}
652+
}
653+
654+
# check spaces before question mark
655+
if($nostr =~ /^(.*)(\w|\)|\]|')\?/i) {
656+
my $m = $1;
657+
my $e = $nostr;
658+
$e =~ s/'?'//g; # ignore these
659+
if($e =~ /^(.*)(\w|\)|\]|')\?/i) {
660+
checkwarn("NOSPACEQ",
661+
$line, length($m)+1, $file, $l,
662+
"missing space before question mark");
663+
}
664+
}
665+
# check spaces after question mark
666+
if($nostr =~ /^(.*)\?\w/i) {
667+
checkwarn("NOSPACEQ",
668+
$line, length($1)+1, $file, $l,
669+
"missing space after question mark");
670+
}
671+
672+
# check spaces before less or greater than
673+
if($nostr =~ /^(.*)(\w|\)|\])[<>]/) {
674+
checkwarn("NOSPACETHAN",
675+
$line, length($1)+1, $file, $l,
676+
"missing space before less or greater than");
677+
}
678+
# check spaces after less or greater than
679+
if($nostr =~ /^(.*)[^-][<>](\w|\(|\[)/) {
680+
checkwarn("NOSPACETHAN",
681+
$line, length($1)+1, $file, $l,
682+
"missing space after less or greater than");
683+
}
684+
606685
# check spaces before close parentheses, unless it was a space or a
607686
# close parenthesis!
608687
if($l =~ /(.*[^\) ]) \)/) {
@@ -712,7 +791,8 @@ sub scanfile {
712791
strtok|
713792
v?sprintf|
714793
(str|_mbs|_tcs|_wcs)n?cat|
715-
LoadLibrary(Ex)?(A|W)?)
794+
LoadLibrary(Ex)?(A|W)?|
795+
_?w?access)
716796
\s*\(
717797
/x) {
718798
checkwarn("BANNEDFUNC",
@@ -731,6 +811,18 @@ sub scanfile {
731811
}
732812
}
733813
}
814+
if($warnings{"STRNCPY"}) {
815+
# scan for use of banned strncpy. This is not a BANNEDFUNC to
816+
# allow for individual enable/disable of this warning.
817+
if($l =~ /^(.*\W)(strncpy)\s*\(/x) {
818+
if($1 !~ /^ *\#/) {
819+
# skip preprocessor lines
820+
checkwarn("STRNCPY",
821+
$line, length($1), $file, $ol,
822+
"use of $2 is banned");
823+
}
824+
}
825+
}
734826
if($warnings{"STDERR"}) {
735827
# scan for use of banned stderr. This is not a BANNEDFUNC to
736828
# allow for individual enable/disable of this warning.
@@ -915,7 +1007,7 @@ sub scanfile {
9151007
checkwarn("COPYRIGHT", 1, 0, $file, "", "Missing copyright statement", 1);
9161008
}
9171009

918-
# COPYRIGHTYEAR is a extended warning so we must first see if it has been
1010+
# COPYRIGHTYEAR is an extended warning so we must first see if it has been
9191011
# enabled in .checksrc
9201012
if(defined($warnings{"COPYRIGHTYEAR"})) {
9211013
# The check for updated copyrightyear is overly complicated in order to

Diff for: ci/checksrc.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ set -e
66

77
cd "$(dirname "$0")/.."
88

9-
perl ./ci/checksrc.pl -i4 -m79 \
10-
-Wsrc/libssh2_config.h \
11-
src/*.[ch] include/*.h example/*.c tests/*.[ch]
9+
git ls-files "*.[ch]" | xargs -n1 \
10+
./ci/checksrc.pl -i4 -m79 -AFOPENMODE -ASNPRINTF -ATYPEDEFSTRUCT

0 commit comments

Comments
 (0)