Skip to content

Commit

Permalink
Fix: Detect const variable declaration in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Gautier committed Nov 19, 2019
1 parent 341f1c6 commit 60cead1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions betty-style.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3054,9 +3054,13 @@ sub process {
# actual declarations
($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
# function pointer declarations
$prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
$prevline =~ /^\+\s+$Declare\s*\(\s*\*+\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
# foo bar; where foo is some local typedef or #define
$prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
$prevline =~ /^\+\s+$Ident(?:\s+|\s*\*+\s*)$Ident\s*[=,;\[]/ ||
# const foo bar; where foo is some local typedef or #define
$prevline =~ /^\+\s+\bconst\b\s+$Ident(?:\s+|\s*\*+\s*)$Ident\s*[=,;\[]/ ||
# foo const bar; where foo is some local typedef or #define
$prevline =~ /^\+\s+$Ident\s+\bconst\b(?:\s+|\s*\*+\s*)$Ident\s*[=,;\[]/ ||
# known declaration macros
$prevline =~ /^\+\s+$declaration_macros/) &&
# for "else if" which can look like "$Ident $Ident"
Expand All @@ -3068,9 +3072,13 @@ sub process {
# looks like a declaration
!($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
# function pointer declarations
$sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
$sline =~ /^\+\s+$Declare\s*\(\s*\*+\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
# foo bar; where foo is some local typedef or #define
$sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
$sline =~ /^\+\s+$Ident(?:\s+|\s*\*+\s*)$Ident\s*[=,;\[]/ ||
# const foo bar; where foo is some local typedef or #define
$sline =~ /^\+\s+\bconst\b\s+$Ident(?:\s+|\s*\*+\s*)$Ident\s*[=,;\[]/ ||
# foo const bar; where foo is some local typedef or #define
$sline =~ /^\+\s+$Ident\s+\bconst\b(?:\s+|\s*\*+\s*)$Ident\s*[=,;\[]/ ||
# known declaration macros
$sline =~ /^\+\s+$declaration_macros/ ||
# start of struct or union or enum
Expand Down
9 changes: 9 additions & 0 deletions tests/style/line_break/line_break5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
EC_KEY *ec_from_pub(uint8_t const pub[EC_PUB_LEN])
{
EC_KEY *key = NULL;
EC_POINT *point = NULL;
EC_GROUP const *group = NULL;
int test_int = 0;

return (key);
}
Empty file.

0 comments on commit 60cead1

Please sign in to comment.