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 <b...@makefile.in>
Signed-off-by: Joe Perches <j...@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.



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

Reply via email to