Skip to contentSkip to conversation

do not initialise globals to 0 or NULL\n

PATCH New Bandan Das 2 participants 2 messages May 29, 2015 Checkpatch

lore
Share & tools
lore

Bandan Das

author
#0 lore raw

Hi Joe,

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:

scripts/checkpatch.pl +1 -1
index 89b1df4..d076d39 100755
@@ -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 ?

Thanks,
Bandan

maintainer
#1 lore raw

PATCH 1/1 checkpatch: Fix "GLOBAL_INITIALISERS" test

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

Fix it.

---

Quoted 1 line · Bandan Das

Hi Joe,

Hi Bandan.

scripts/checkpatch.pl

Quoted 6 lines

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:

scripts/checkpatch.pl +0 -0

[]

Quoted 10 lines
scripts/checkpatch.pl +1 -1
@@ -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) &&
Quoted 2 lines

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(-)
scripts/checkpatch.pl +2 -2
index 4650c04..e46414d 100755
@@ -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.