diff options
-rw-r--r-- | util/check-format-test-negatives.c | 4 | ||||
-rw-r--r-- | util/check-format-test-positives.c | 5 | ||||
-rwxr-xr-x | util/check-format.pl | 7 |
3 files changed, 13 insertions, 3 deletions
diff --git a/util/check-format-test-negatives.c b/util/check-format-test-negatives.c index c9f77ecf6c..01216718fd 100644 --- a/util/check-format-test-negatives.c +++ b/util/check-format-test-negatives.c @@ -150,6 +150,10 @@ int f(void) /* hanging_stmt; } +/* should not trigger: constant on LHS of comparison or assignment operator */ +X509 *x509 = NULL; +int y = a + 1 < b; + const OPTIONS passwd_options[] = { {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"}, #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0) diff --git a/util/check-format-test-positives.c b/util/check-format-test-positives.c index 5174a2b530..89dcf073ce 100644 --- a/util/check-format-test-positives.c +++ b/util/check-format-test-positives.c @@ -75,7 +75,8 @@ int f (int a, /*@ space after fn before '(', reported unless sloppy-spc */ long l) /*@ one-letter name 'l' */ { int /*@ code after '{' opening a block */ xx = 1) + /*@ unexpected closing parenthesis */ - 2] - /*@ unexpected closing bracket */ + 0L < /*@ constant on LHS of comparison operator */ + a] - /*@ unexpected closing bracket */ 3: * /*@ unexpected ':' (without preceding '?') within expr */ 4}; /*@ unexpected closing brace within expression */ char y[] = { /*@0 unclosed brace within initializer/enum expression */ @@ -91,7 +92,7 @@ int f (int a, /*@ space after fn before '(', reported unless sloppy-spc */ b, /*@ expr indent as on line above, accepted if sloppy-hang */ b, /*@ expr indent off -8 but @ extra indent accepted if sloppy-hang */ "again aligned" /*@ expr indent off by -9 (left of stmt indent, */ "right", - 123 == /*@ .. so reported also with sloppy-hang; this line is too long */ 456 + abc == /*@ .. so reported also with sloppy-hang; this line is too long */ 456 # 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 ':' */ diff --git a/util/check-format.pl b/util/check-format.pl index 2a9adc6fb8..481eda8b36 100755 --- a/util/check-format.pl +++ b/util/check-format.pl @@ -846,7 +846,12 @@ while (<>) { # loop over all lines of all input files } } - report("one-letter name '$2'") if (m/(^|.*\W)([lIO])(\W.*|$)/); # single-letter name 'l', 'I', or 'O' + report("single-letter name '$2'") if (m/(^|.*\W)([IO])(\W.*|$)/); # single-letter name 'I' or 'O' # maybe re-add 'l'? + # constant on LHS of comparison or assignment, e.g., NULL != x or 'a' < c, but not a + 1 == b + report("constant on LHS of '$2'") + if (m/(['"]|([\+\-\*\/\/%\&\|\^<>]\s*)?\W[0-9]+L?|NULL)\s*([\!<>=]=|[<=>][^<>])/ && $2 eq ""); + + # TODO report #if 0 and #if 1 # TODO report empty line within local variable definitions |