check-format.pl: Fix report on constant on LHS of comparison/assignment
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Thu, 6 Jan 2022 21:05:22 +0000 (22:05 +0100)
committerPauli <ppzgs1@gmail.com>
Sun, 9 Jan 2022 02:19:52 +0000 (13:19 +1100)
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17434)

util/check-format-test-negatives.c
util/check-format.pl

index f4c0908e4c23b434d40af0b004818141eaa71ad4..8f6ed23ee72e75680e32323e654d368e71220e83 100644 (file)
@@ -188,6 +188,7 @@ int f(void) /*
 /* should not trigger: constant on LHS of comparison or assignment operator */
 X509 *x509 = NULL;
 int y = a + 1 < b;
+int ret, was_NULL = *certs == NULL;
 
 const OPTIONS passwd_options[] = {
     {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
index aa2566e28e3f3c36526e668f943261f03a49786b..8861b2bd8ac886ed532f0a5de224dc75e858de0e 100755 (executable)
@@ -886,7 +886,8 @@ while (<>) { # loop over all lines of all input files
     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 '$3'")
-        if (m/(['"]|([\+\-\*\/\/%\&\|\^<>]\s*)?\W[0-9]+L?|NULL)\s*([\!<>=]=|[<=>][^<>])/ && $2 eq "");
+        if (m/(['"]|([\+\-\*\/\/%\&\|\^<>]\s*)?\W[0-9]+L?|\WNULL)\s*([\!<>=]=|[<=>])([<>]?)/ &&
+            $2 eq "" && (($3 ne "<" && $3 ne "='" && $3 ne ">") || $4 eq ""));
 
     # TODO report #if 0 and #if 1