mirror of
https://github.com/curl/curl.git
synced 2026-07-23 17:57:17 +03:00
checksrc: detect curlx_safefree() opportunities
Follow-up tobcd0497c81#21700 Follow-up to1c3289c85e#21684 Follow-up toc0f0e400e0#5968 Follow-up to0f4a03cbb6Closes #21703
This commit is contained in:
parent
f2692b54f7
commit
419b1c0b75
3 changed files with 33 additions and 1 deletions
|
|
@ -201,6 +201,7 @@ my %warnings = (
|
|||
'TRAILINGSPACE' => 'Trailing whitespace on the line',
|
||||
'TYPEDEFSTRUCT' => 'typedefed struct',
|
||||
'UNUSEDIGNORE' => 'a warning ignore was not used',
|
||||
'USESAFEFREE' => 'replace curlx_free() + NULL assignment with curlx_safefree()',
|
||||
);
|
||||
|
||||
sub readskiplist {
|
||||
|
|
@ -532,6 +533,8 @@ sub scanfile {
|
|||
my $l = "";
|
||||
my $prep = 0;
|
||||
my $prevp = 0;
|
||||
my $prevfreeindent = "";
|
||||
my $prevfreevar = "";
|
||||
|
||||
if($verbose) {
|
||||
printf "Checking file: $file\n";
|
||||
|
|
@ -973,6 +976,24 @@ sub scanfile {
|
|||
$line, length($1), $file, $ol, "no space before label");
|
||||
}
|
||||
|
||||
if($prevfreevar ne "") {
|
||||
if(rindex($l, "$prevfreeindent$prevfreevar = NULL;", 0) == 0) {
|
||||
checkwarn("USESAFEFREE",
|
||||
$line, length($prevfreeindent), $file, $ol,
|
||||
"replace curlx_free() + NULL assignment with curlx_safefree()");
|
||||
}
|
||||
}
|
||||
if($l) {
|
||||
if($l =~ /^( *)curlx_free\(([^)]+)\);/) {
|
||||
$prevfreeindent = $1;
|
||||
$prevfreevar = $2;
|
||||
}
|
||||
else {
|
||||
$prevfreeindent = "";
|
||||
$prevfreevar = "";
|
||||
}
|
||||
}
|
||||
|
||||
# scan for use of banned functions
|
||||
my $bl = $l;
|
||||
again:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue