diff --git a/betty-style.pl b/betty-style.pl index 7859d7d..f59dc22 100755 --- a/betty-style.pl +++ b/betty-style.pl @@ -2234,6 +2234,7 @@ sub process { $fixlinenr = -1; my $nbfunc = 0; my $inscope = 0; + my $infunction_params = 0; my $funclines = 0; foreach my $line (@lines) { @@ -3593,12 +3594,12 @@ sub process { } # Check for global variables (not allowed). - if ($allow_global_variables == 0) { - if ($inscope == 0 && - ($line =~ /^\+\s*$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ || - $line =~ /^\+\s*$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(].*;/ || - $line =~ /^\+\s*$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || - $line =~ /^\+\s*$declaration_macros/)) { + if ($allow_global_variables == 0 && + $inscope == 0 && $infunction_params == 0) { + if ($line =~ /^\+\s*$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ || + $line =~ /^\+\s*$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(].*;/ || + $line =~ /^\+\s*$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || + $line =~ /^\+\s*$declaration_macros/) { ERROR("GLOBAL_DECLARATION", "global variables are not allowed\n" . $herecurr); } @@ -3671,6 +3672,21 @@ sub process { } } +#check if in function parameters section + if ($line =~ /\b$Type\s+$Ident\s*\(/ || + $line =~ /\b$Ident(?:\s+|\s*\*\s*)$Ident\s*\(/ && + $line !~ /(?:else|if|while|for|switch)/) { + if ($line =~ /(\()/g) { + $infunction_params += $#-; + } + if ($line =~ /(\))/g) { + $infunction_params -= $#-; + } + } + if ($infunction_params > 0 && $line =~ /(\))/g) { + $infunction_params -= $#-; + } + # check for uses of DEFINE_PCI_DEVICE_TABLE if ($line =~ /\bDEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=/) { if (WARN("DEFINE_PCI_DEVICE_TABLE", diff --git a/tests/style/variables/variables2.c b/tests/style/variables/variables2.c new file mode 100644 index 0000000..f3c1946 --- /dev/null +++ b/tests/style/variables/variables2.c @@ -0,0 +1,9 @@ +/* + * Fixed: token_t *token was detected as a global variable + */ + +static const char *process_token(command_chain_t *chain, command_t **cmd, + token_t *token, const char *start) +{ + return (NULL); +} diff --git a/tests/style/variables/variables2.expected b/tests/style/variables/variables2.expected new file mode 100644 index 0000000..e69de29