Skip to content

Commit

Permalink
Fix: Detec global variables declaration outside of any scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Gautier committed Feb 10, 2017
1 parent 87ad641 commit ebde92c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions betty-style.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3578,10 +3578,11 @@ sub process {

# Check for global variables (not allowed).
if ($allow_global_variables == 0) {
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ ||
$line =~ /^\+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
$line =~ /^\+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
$line =~ /^\+$declaration_macros/) {
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/)) {
ERROR("GLOBAL_DECLARATION",
"global variables are not allowed\n" . $herecurr);
}
Expand Down
1 change: 1 addition & 0 deletions tests/style/variables/variables0.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
int i;
int global_var;
int indented_global = 98;
unsigned int another = 12;
void (*global_func_ptr)(int, int);
3 changes: 2 additions & 1 deletion tests/style/variables/variables0.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ tests/style/variables/variables0.c:1: ERROR: global variables are not allowed
tests/style/variables/variables0.c:2: ERROR: global variables are not allowed
tests/style/variables/variables0.c:3: ERROR: global variables are not allowed
tests/style/variables/variables0.c:4: ERROR: global variables are not allowed
total: 4 errors, 0 warnings, 4 lines checked
tests/style/variables/variables0.c:5: ERROR: global variables are not allowed
total: 5 errors, 0 warnings, 5 lines checked

0 comments on commit ebde92c

Please sign in to comment.