checksrc: add STRNCPY as an opt-in rule to detect and error on strncpy

make "lib/.checksrc" enable it

Closes #14830
This commit is contained in:
Daniel Stenberg 2024-09-09 10:15:49 +02:00
parent 344a177aac
commit 80df6a5c12
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 14 additions and 0 deletions

View File

@ -1 +1,2 @@
enable STRERROR
enable STRNCPY

View File

@ -50,6 +50,7 @@ my @ignore_line;
my %warnings_extended = (
'COPYRIGHTYEAR' => 'copyright year incorrect',
'STRERROR', => 'strerror() detected',
'STRNCPY', => 'strncpy() detected',
'STDERR', => 'stderr detected',
);
@ -751,6 +752,18 @@ sub scanfile {
}
}
}
if($warnings{"STRNCPY"}) {
# scan for use of banned strncpy. This is not a BANNEDFUNC to
# allow for individual enable/disable of this warning.
if($l =~ /^(.*\W)(strncpy)\s*\(/x) {
if($1 !~ /^ *\#/) {
# skip preprocessor lines
checkwarn("STRNCPY",
$line, length($1), $file, $ol,
"use of $2 is banned");
}
}
}
if($warnings{"STDERR"}) {
# scan for use of banned stderr. This is not a BANNEDFUNC to
# allow for individual enable/disable of this warning.