mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Bandan Das <bsd@makefile.in>, Andy Whitcroft <apw@canonical.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: Fix "GLOBAL_INITIALISERS" test
Date: Fri, 29 May 2015 02:12:18 -0700	[thread overview]
Message-ID: <1432890738.29807.6.camel@perches.com> (raw)
In-Reply-To: <jpg4mmwqcdv.fsf@aqua.home.waltham>

commit d5e616fc1c1d ("checkpatch: add a few more --fix corrections")
broke the GLOBAL_INITIALISERS test with bad parentheses and optional
leading spaces.

Fix it.

Reported-by: Bandan Das <bsd@makefile.in>
Signed-off-by: Joe Perches <joe@perches.com>
---
On Thu, 2015-05-28 at 23:41 -0400, Bandan Das wrote:
> Hi Joe,

Hi Bandan.

> Sorry, I am very Perl illiterate but I was deliberately trying to hit the
> "do not initialize globals" message from checkpatch.pl and can't seem to.
> 
> Looking at the corresponding regexp, it seems the correct pattern should be:
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -3169,7 +3169,7 @@ sub process {
>                 }
>  
>  # check for global initialisers.
> -               if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
> +               if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/) {
>                         if (ERROR("GLOBAL_INITIALISERS",
>                                   "do not initialise globals to 0 or NULL\n" .
>                                       $herecurr) &&
> 
> which matches zero or more of $Modifier followed by zero or more of a space.
> Or am I missing something ?

No, you're right, thanks, but the proper fix is a bit more
than that and it's below.

 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4650c04..e46414d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3176,12 +3176,12 @@ sub process {
 		}
 
 # check for global initialisers.
-		if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
+		if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*(?:0|NULL|false)\s*;/) {
 			if (ERROR("GLOBAL_INITIALISERS",
 				  "do not initialise globals to 0 or NULL\n" .
 				      $herecurr) &&
 			    $fix) {
-				$fixed[$fixlinenr] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/;
+				$fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/$1;/;
 			}
 		}
 # check for static initialisers.




      reply	other threads:[~2015-05-29  9:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29  3:41 do not initialise globals to 0 or NULL\n Bandan Das
2015-05-29  9:12 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432890738.29807.6.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=bsd@makefile.in \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®