lkml.org 
[lkml]   [2015]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] checkpatch: Fix "GLOBAL_INITIALISERS" test
From
Date
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.




\
 
 \ /
  Last update: 2015-05-29 11:41    [W:0.029 / U:75.400 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site