lint/checkpatch: Update 'check for illegal assignment in if conditional'
This reduce the difference with linux v6.5-rc4. Change-Id: I63b3561471d3bd0ebfe7e5733c6dd6fb673904e0 Signed-off-by: Elyes Haouas <ehaouas@noos.fr> Reviewed-on: https://review.coreboot.org/c/coreboot/+/65829 Reviewed-by: Martin L Roth <gaumless@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
a9e4567c4b
commit
d2bb4858f3
|
@ -5180,10 +5180,34 @@ sub process {
|
|||
defined($stat) && defined($cond) &&
|
||||
$line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
|
||||
my ($s, $c) = ($stat, $cond);
|
||||
my $fixed_assign_in_if = 0;
|
||||
|
||||
if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
|
||||
ERROR("ASSIGN_IN_IF",
|
||||
"do not use assignment in if condition\n" . $herecurr);
|
||||
if (ERROR("ASSIGN_IN_IF",
|
||||
"do not use assignment in if condition\n" . $herecurr) &&
|
||||
$fix && $perl_version_ok) {
|
||||
if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) {
|
||||
my $space = $1;
|
||||
my $not = $2;
|
||||
my $statement = $3;
|
||||
my $assigned = $4;
|
||||
my $test = $8;
|
||||
my $against = $9;
|
||||
my $brace = $15;
|
||||
fix_delete_line($fixlinenr, $rawline);
|
||||
fix_insert_line($fixlinenr, "$space$statement;");
|
||||
my $newline = "${space}if (";
|
||||
$newline .= '!' if defined($not);
|
||||
$newline .= '(' if (defined $not && defined($test) && defined($against));
|
||||
$newline .= "$assigned";
|
||||
$newline .= " $test $against" if (defined($test) && defined($against));
|
||||
$newline .= ')' if (defined $not && defined($test) && defined($against));
|
||||
$newline .= ')';
|
||||
$newline .= " {" if (defined($brace));
|
||||
fix_insert_line($fixlinenr + 1, $newline);
|
||||
$fixed_assign_in_if = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Find out what is on the end of the line after the
|
||||
|
|
Loading…
Reference in New Issue