checksrc: introduce 'banfunc' to ban specific functions

Use 'banfunc' and 'allowfunc' in .checksrc to specify which functions to
ban or allow to be used. This saves us from having to edit the script
going forward when we want to ban or allow specific functions.

This replaces a set of previous rules and all banned functions are now
checked with the BANNEDFUNC rule.

There is a set of default banned functions, shown by invoking
./checksrc.

Also, -a and -b options are added to specify allowed or banned functions
on the command line.

Closes #15835
This commit is contained in:
Daniel Stenberg 2024-12-27 09:21:56 +01:00
parent 66e5351e0a
commit c445b7426a
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
9 changed files with 92 additions and 80 deletions

View file

@ -16,7 +16,7 @@ checksrc
</name>
<command type="perl">
%SRCDIR/../scripts/checksrc.pl %LOGDIR/code%TESTNUMBER.c
%SRCDIR/../scripts/checksrc.pl -bmagicbad -balsobad %LOGDIR/code%TESTNUMBER.c
</command>
<file name="%LOGDIR/code%TESTNUMBER.c">
/* test source code
@ -71,7 +71,7 @@ void startfunc(int a, int b) {
}
int a = sizeof int;
int a = snprintf(buffer, sizeof(buffer), "%d", 99);
int a = magicbad(buffer, alsobad(buffer), "%d", 99);
int moo = hej?wrong:a>b;
int moo2 = wrong2:(a)>(b);
@ -162,9 +162,12 @@ void startfunc(int a, int b) {
./%LOGDIR/code1185.c:52:16: warning: sizeof without parenthesis (SIZEOFNOPAREN)
int a = sizeof int;
^
./%LOGDIR/code1185.c:53:10: warning: use of snprintf is banned (SNPRINTF)
int a = snprintf(buffer, sizeof(buffer), "%d", 99);
./%LOGDIR/code1185.c:53:10: warning: use of magicbad is banned (BANNEDFUNC)
int a = magicbad(buffer, alsobad(buffer), "%d", 99);
^
./%LOGDIR/code1185.c:53:27: warning: use of alsobad is banned (BANNEDFUNC)
int a = magicbad(buffer, alsobad(buffer), "%d", 99);
^
./%LOGDIR/code1185.c:54:21: warning: missing space before colon (NOSPACEC)
int moo = hej?wrong:a>b;
^
@ -201,7 +204,7 @@ void startfunc(int a, int b) {
./%LOGDIR/code1185.c:1:1: error: Missing closing comment (OPENCOMMENT)
^
checksrc: 0 errors and 38 warnings
checksrc: 0 errors and 39 warnings
</stdout>
<errorcode>
5