lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1424375741.18211.4.camel@perches.com>
Date:	Thu, 19 Feb 2015 11:55:41 -0800
From:	Joe Perches <joe@...ches.com>
To:	Marek Lindner <mareklindner@...mailbox.ch>
Cc:	"b.a.t.m.a.n" <b.a.t.m.a.n@...ts.open-mesh.org>,
	linux-kernel@...r.kernel.org,
	Dan Carpenter <dan.carpenter@...cle.com>
Subject: Re: checkpatch: CHECK: No space is necessary after a cast

On Thu, 2015-02-19 at 13:35 +0800, Marek Lindner wrote:
> Hi Joe,

Hi Marek

> we have come across a checkpatch false-positive:
[]
> 	BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6);
> CHECK: No space is necessary after a cast
> #440: FILE: main.c:440:
> +       BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6);
[]
> Can you make a suggestion / patch for checkpatch to better handle this case ?

The "sizeof" test in the current script doesn't work.

I believe the patch below works with no false positives
but <shrug> it's perl regexes against odd coding styles
and weird macros, who knows for sure...

I did run it against drivers/, net/ and include/

Give this a try:
---
 scripts/checkpatch.pl | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d124359..2f5bb27 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2552,9 +2552,15 @@ sub process {
 			}
 		}
 
-		if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ &&
-		    (!defined($1) || $1 !~ /sizeof\s*/)) {
-			if (CHK("SPACING",
+# check for space after cast like "(int) foo" or "(struct foo) bar"
+# avoid checking a few false positives:
+#   "sizeof(<type>)" or "__alignof__(<type>)"
+#   function pointer declarations like "(*foo)(int) = bar;"
+#   structure definitions like "(struct foo) { 0 };"
+#   multiline macros that define functions
+		if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$))/ &&
+		    (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
+			if (CHK("SPACING",
 				"No space is necessary after a cast\n" . $herecurr) &&
 			    $fix) {
 				$fixed[$fixlinenr] =~


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ