Skip to content

Commit

Permalink
Fix: Declaration of array of pointer to functions not detected and th…
Browse files Browse the repository at this point in the history
…rowing missing blank line
  • Loading branch information
Alexandre Gautier committed Mar 5, 2018
1 parent 9e78f17 commit e6fc6de
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions betty-style.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3078,9 +3078,13 @@ sub process {
# bitfield continuation
$sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
# other possible extensions of declaration lines
$sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
$sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/ ||
# array of function pointers
$sline =~ /\+\s+($Ident)\s*\(\*+$Ident(?:\[\S*\])?\)\s*\((?:(?:,\s*)?$Ident)*\);/ ||
$sline =~ /\+\s+($Ident)\s*\(\*+$Ident(?:\[\S*\])?\)\s*\((?:(?:,\s*)?$Ident)*\)\s*=/) &&
# indentation of previous and current line are the same
(($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {

if (WARN("LINE_SPACING",
"Missing a blank line after declarations\n" . $hereprev) &&
$fix) {
Expand Down Expand Up @@ -3908,7 +3912,7 @@ sub process {
if ($line =~ /(})/g) {
$inscope -= $#-;
}

if ($inscope >= 1 && $infunc == 1) {
$funclines++;
if ($funclines > $max_func_length + 1) {
Expand Down
38 changes: 38 additions & 0 deletions tests/style/line_break/line_break3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
int (*get_op_func(char *s))(int, int)
{
char key[] = {'+', '-', '*', '/', '%'};
int i = 0;
int (*f[])(int, int) = {op_add, op_sub, op_mul, op_div, op_mod};

while (i < 5)
{
return (0);
}
return (0);
}

int (*get_op_func(char *s))(int, int)
{
char key[] = {'+', '-', '*', '/', '%'};
int i = 0;
int (*f[5])(int, int);

while (i < 5)
{
return (0);
}
return (0);
}

int (*get_op_func(char *s))(int, int)
{
char key[] = {'+', '-', '*', '/', '%'};
int i = 0;
int (*f[5])(int, int) = {op_add, op_sub, op_mul, op_div, op_mod};

while (i < 5)
{
return (0);
}
return (0);
}
Empty file.

0 comments on commit e6fc6de

Please sign in to comment.