do not initialise globals to 0 or NULL\n
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
@@ -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
Joe Perches
maintainerPATCH 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
@@ -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.