/*@ whitespace at EOL: */
// /*@ end-of-line comment style not allowed (for C90 compatibility) */
/*@0 intra-line comment indent off by 1, reported unless sloppy-cmt */
-/*X */ /*@2 no space nor '*' after comment start, reported unless sloppy-spc */
-/* X*/ /*@ no space before comment end , reported unless sloppy-spc */
+/*X */ /*@2 missing spc or '*' after comment start reported unless sloppy-spc */
+/* X*/ /*@ missing space before comment end , reported unless sloppy-spc */
/*@ comment starting delimiter: /* inside intra-line comment */
/*@0
*@ above multi-line comment start indent off by 1, reported unless sloppy-cmt; this comment line is too long
} s_type; /*@ statement/type declaration indent off by 4 */
int* somefunc(); /*@ no space before '*' in type decl, r unless sloppy-spc */
void main(int n) { /*@ opening brace at end of function definition header */
- for (;;n++) { /*@ no space after ';', reported unless sloppy-spc */
+ for (; ; ) ; /*@ space before ')', reported unless sloppy-spc */
+ for ( ; x; y) ; /*@2 space after '(' and before ';', unless sloppy-spc */
+ for (;;n++) { /*@ missing space after ';', reported unless sloppy-spc */
return; /*@0 (1-line) single statement in braces */
}} /*@2 code after '}' outside expr */
} /*@ unexpected closing brace (too many '}') outside expr */
# define MAC(A) (A) /*@ nesting indent of preprocessor directive off by 1 */
? 1 /*@ hanging expr indent off by 1 */
: 2); /*@ hanging expr indent off by 2, or 1 for leading ':' */
- if(a /*@ no space after 'if', reported unless sloppy-spc */
+ if(a /*@ missing space after 'if', reported unless sloppy-spc */
/*@0 intra-line comment indent off by -1 (not: by 3 due to '&&') */
&& ! 0 /*@2 space after '!', reported unless sloppy-spc */
|| b == /*@ hanging expr indent off by 2, or -2 for leading '||' */
- (xx+= 2) + /*@ no space before '+=', reported unless sloppy-spc */
- (a^ 1) + /*@ no space before '^', reported unless sloppy-spc */
- a %2 / /*@ no space after '%', reported unless sloppy-spc */
+ (xx+= 2) + /*@ missing space before '+=', reported unless sloppy-spc */
+ (a^ 1) + /*@ missing space before '^', reported unless sloppy-spc */
+ a %2 / /*@ missing space after '%', reported unless sloppy-spc */
1 +/* */ /*@ no space before comment, reported unless sloppy-spc */
/* */+ /*@ no space after comment, reported unless sloppy-spc */
s. e_member) /*@ space after '.', reported unless sloppy-spc */
if (a ++) /*@ space before postfix '++', reported unless sloppy-spc */
{ /*@ {' not on same line as preceding 'if' */
c; /*@0 single stmt in braces, reported on 1-stmt */
- } else /*@ no '{' on same line after '} else' */
+ } else /*@ missing '{' on same line after '} else' */
{ /*@ statement indent off by 2 */
d; /*@0 single stmt in braces, reported on 1-stmt */
} /*@ statement indent off by 6 */
while ( 2); /*@ space after '(', reported unless sloppy-spc */
b; c; /*@ more than one statement per line */
outer: /*@ outer label special indent off by 1 */
- do{ /*@ no space before '{', reported unless sloppy-spc */
+ do{ /*@ missing space before '{', reported unless sloppy-spc */
inner: /*@ inner label normal indent off by 1 */
f (3, /*@ space after fn before '(', reported unless sloppy-spc */
4); /*@0 false negative: should report single stmt in braces */
} /*@0 'while' not on same line as preceding '}' */
- while (a+ 0); /*@2 no space before '+', reported unless sloppy-spc */
+ while (a+ 0); /*@2 missing space before '+', reported unless sloppy-spc */
switch (b ) { /*@ space before ')', reported unless sloppy-spc */
case 1: /*@ 'case' special statement indent off by -1 */
- case(2): /*@ no space after 'case', reported unless sloppy-spc */
+ case(2): /*@ missing space after 'case', reported unless sloppy-spc */
default: ; /*@ code after 'default:' */
} /*@ statement indent off by -4 */
- return( /*@ no space after 'return', reported unless sloppy-spc */
+ return( /*@ missing space after 'return', reported unless sloppy-spc */
x); } /*@ code before block-level '}' */
/* Here the tool should stop complaining apart from the below issues at EOF */
my ($head, $tail) = (substr($str, 0, $i).$1, $3);
$i += length($1) + length($2) - 1;
- # stop at terminator outside 'for(..;..;..)', assuming that 'for' is followed by '('
+ # stop at terminator outside 'for (..;..;..)', assuming that 'for' is followed by '('
return $i if $c eq ";" && (!$in_paren_expr || @nested_indents == 0);
my $in_stmt = $in_expr || @nested_symbols != 0; # not: || $in_typedecl != 0
# treat remaining blinded comments and string literal contents as (single) space during matching below
$intra_line =~ s/@+/ /g; # note that extra SPC has already been handled above
$intra_line =~ s/\s+$//; # strip any (resulting) space at EOL
- $intra_line =~ s/(for\s*\([^;]*);;(\))/"$1$2"/eg; # strip trailing ';;' in for (;;)
- $intra_line =~ s/(for\s*\([^;]+;[^;]+);(\))/"$1$2"/eg; # strip trailing ';' in for (;;)
- $intra_line =~ s/(for\s*\();(;)/"$1$2"/eg; # replace leading ';;' in for (;;) by ';'
+ # replace ';;' or '; ;' by ';' in "for(;;)" and in "for (...)" unless "..." contains just SPC and ';' characters:
+ $intra_line =~ s/((^|\W)for\s*\()([^;]*?)(\s*)(;\s?);(\s*)([^;]*)(\))/
+ "$1$3$4".("$3$4$5$6$7" eq ";" || $3 ne "" || $7 ne "" ? "" : $5).";$6$7$8"/eg;
+ # strip trailing ';' or '; ' in "for (...)" except in "for (;;)" or "for (;; )":
+ $intra_line =~ s/((^|\W)for\s*\()([^;]*(;[^;]*)?)(;\s?)(\))/
+ "$1$3".($3 eq ";" ? $5 : "")."$6"/eg;
$intra_line =~ s/(=\s*)\{ /"$1@ "/eg; # do not report {SPC in initializers such as ' = { 0, };'
$intra_line =~ s/, \};/, @;/g; # do not report SPC} in initializers such as ' = { 0, };'
report("space before '$1'") if $intra_line =~ m/[\w)\]]\s+(\+\+|--)/; # postfix ++/-- with preceding space
report("space before '$1'") if $intra_line =~ m/\s(\.|->)/; # '.' or '->' with preceding space
report("space after '$1'") if $intra_line =~ m/(\.|->)\s/; # '.' or '->' with following space
$intra_line =~ s/\-\>|\+\+|\-\-/@/g; # blind '->,', '++', and '--'
- report("space before '$1'") if $intra_line =~ m/[^:)]\s+(;)/; # space before ';' but not after ':' or ')'
+ report("space before '$1'") if $intra_line =~ m/[^:)]\s+(;)/; # space before ';' but not after ':' or ')' # note that
+ # exceptions for "for (;; )" are handled above
report("space before '$1'") if $intra_line =~ m/\s([,)\]])/; # space before ,)]
report("space after '$1'") if $intra_line =~ m/([(\[~!])\s/; # space after ([~!
report("space after '$1'") if $intra_line =~ m/(defined)\s/; # space after 'defined'