summaryrefslogtreecommitdiff
path: root/lib/checksrc.pl
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-09-08 11:27:49 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-09-09 07:53:42 +0200
commit2f0bb864c126892afc822e0cf5547d7ea5094212 (patch)
treea22cb9fb03b3b731923cc1ffe4245b0a606297fe /lib/checksrc.pl
parent71f9a8fa6f52723c0492c61ded070386706e99c6 (diff)
downloadcurl-2f0bb864c126892afc822e0cf5547d7ea5094212.tar.gz
lib: don't use strerror()
We have and provide Curl_strerror() internally for a reason: strerror() is not necessarily thread-safe so we should always try to avoid it. Extended checksrc to warn for this, but feature the check disabled by default and only enable it in lib/ Closes #7685
Diffstat (limited to 'lib/checksrc.pl')
-rwxr-xr-xlib/checksrc.pl28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/checksrc.pl b/lib/checksrc.pl
index a35535c19..ac7e3847e 100755
--- a/lib/checksrc.pl
+++ b/lib/checksrc.pl
@@ -47,6 +47,7 @@ my @ignore_line;
my %warnings_extended = (
'COPYRIGHTYEAR' => 'copyright year incorrect',
+ 'STRERROR', => 'strerror() detected',
);
my %warnings = (
@@ -87,7 +88,7 @@ my %warnings = (
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
'EMPTYLINEBRACE' => 'Empty line before the open brace',
'EQUALSNULL' => 'if/while comparison with == NULL',
- 'NOTEQUALSZERO' => 'if/while comparison with != 0'
+ 'NOTEQUALSZERO', => 'if/while comparison with != 0',
);
sub readskiplist {
@@ -238,9 +239,17 @@ if(!$file) {
print " -i<n> Indent spaces. Default: 2\n";
print " -m<n> Maximum line length. Default: 79\n";
print "\nDetects and warns for these problems:\n";
- for(sort keys %warnings) {
- printf (" %-18s: %s\n", $_, $warnings{$_});
+ my @allw = keys %warnings;
+ push @allw, keys %warnings_extended;
+ for my $w (sort @allw) {
+ if($warnings{$w}) {
+ printf (" %-18s: %s\n", $w, $warnings{$w});
+ }
+ else {
+ printf (" %-18s: %s[*]\n", $w, $warnings_extended{$w});
+ }
}
+ print " [*] = disabled by default\n";
exit;
}
@@ -638,7 +647,18 @@ sub scanfile {
$line, length($1), $file, $ol,
"use of $2 is banned");
}
-
+ if($warnings{"STRERROR"}) {
+ # scan for use of banned strerror. This is not a BANNEDFUNC to
+ # allow for individual enable/disable of this warning.
+ if($l =~ /^(.*\W)(strerror)\s*\(/x) {
+ if($1 !~ /^ *\#/) {
+ # skip preprocessor lines
+ checkwarn("STRERROR",
+ $line, length($1), $file, $ol,
+ "use of $2 is banned");
+ }
+ }
+ }
# scan for use of snprintf for curl-internals reasons
if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) {
checkwarn("SNPRINTF",