History

checkpatch: add test for char * arrays that could be static const

static const char* arrays create smaller text as each function call does not have to populate the array. Emit a warning when char *arrays aren't static const and the array is not apparently global by being declared in the first column.

Joe Perches committed 12 years ago

Commit 9b0fa601 parent 447432f1 file · +7 −0Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+7−0
@@ -2675,6 +2675,13 @@ sub process { · 2674 unmodified lines
26752675 $herecurr);
26762676 }
26772677
2678+# check for non-global char *foo[] = {"bar", ...} declarations.
2679+ if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
2680+ WARN("STATIC_CONST_CHAR_ARRAY",
2681+ "char * array declaration might be better as static const\n" .
2682+ $herecurr);
2683+ }
2684+
26782685 # check for function declarations without arguments like "int foo()"
26792686 if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
26802687 if (ERROR("FUNCTION_WITHOUT_ARGS",