History

checkpatch: handle do without braces if we have enough context

If we have sufficient context detect and handle do without braces ({). Else these incorrectly trigger a trailing statements error for the associated while.

Andy Whitcroft committed 18 years ago

Commit 170d3a21 parent a6a84061 file · +24 −3Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+24−3
@@ -1051,6 +1051,7 @@ sub process { · 1050 unmodified lines
10511051
10521052 # suppression flags
10531053 my %suppress_ifbraces;
1054+ my %suppress_whiletrailers;
10541055
10551056 # Pre-scan the patch sanitizing the lines.
10561057 # Pre-scan the patch looking for any __setup documentation.
@@ -1156,6 +1157,7 @@ sub process { · 99 unmodified lines
11561157 $prev_values = 'E';
11571158
11581159 %suppress_ifbraces = ();
1160+ %suppress_whiletrailers = ();
11591161 next;
11601162
11611163 # track the line number as we move through the hunk, note that
@@ -1301,9 +1303,9 @@ sub process { · 139 unmodified lines
13011303 }
13021304
13031305 # Check for potential 'bare' types
1304− my ($stat, $cond, $line_nr_next, $remain_next);
1306+ my ($stat, $cond, $line_nr_next, $remain_next, $off_next);
13051307 if ($realcnt && $line =~ /.\s*\S/) {
1306− ($stat, $cond, $line_nr_next, $remain_next) =
1308+ ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
13071309 ctx_statement_block($linenr, $realcnt, 0);
13081310 $stat =~ s/\n./\n /g;
13091311 $cond =~ s/\n./\n /g;
@@ -1952,7 +1954,26 @@ sub process { · 642 unmodified lines
19521954
19531955 # Check for illegal assignment in if conditional -- and check for trailing
19541956 # statements after the conditional.
1955− if ($line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
1957+ if ($line =~ /do\s*(?!{)/) {
1958+ my ($stat_next) = ctx_statement_block($line_nr_next,
1959+ $remain_next, $off_next);
1960+ $stat_next =~ s/\n./\n /g;
1961+ ##print "stat<$stat> stat_next<$stat_next>\n";
1962+
1963+ if ($stat_next =~ /^\s*while\b/) {
1964+ # If the statement carries leading newlines,
1965+ # then count those as offsets.
1966+ my ($whitespace) =
1967+ ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
1968+ my $offset =
1969+ statement_rawlines($whitespace) - 1;
1970+
1971+ $suppress_whiletrailers{$line_nr_next +
1972+ $offset} = 1;
1973+ }
1974+ }
1975+ if (!defined $suppress_whiletrailers{$linenr} &&
1976+ $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
19561977 my ($s, $c) = ($stat, $cond);
19571978
19581979 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {