]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Fixing empty block and never-executed-statement bug
authorMaria Matejka <mq@ucw.cz>
Tue, 13 Aug 2019 14:45:27 +0000 (16:45 +0200)
committerMaria Matejka <mq@ucw.cz>
Tue, 13 Aug 2019 14:45:27 +0000 (16:45 +0200)
filter/config.Y
filter/test.conf

index a67a72a8354f2e867489a505288d322bfc5993ce..340053ba7b11108a22700c2c37a5d78f25696fba 100644 (file)
@@ -446,7 +446,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
 %nonassoc THEN
 %nonassoc ELSE
 
-%type <xp> cmds_int
+%type <xp> cmds_int cmd_prep
 %type <x> term block cmd cmds constant constructor print_list var_list function_call symbol_value bgp_path_expr bgp_path bgp_path_tail
 %type <fda> dynamic_attr
 %type <fsa> static_attr
@@ -624,17 +624,25 @@ cmds: /* EMPTY */ { $$ = NULL; }
  | cmds_int { $$ = $1.begin; }
  ;
 
-cmds_int: cmd {
+cmd_prep: cmd {
   $$.begin = $$.end = $1;
-  while ($$.end->next)
-    $$.end = $$.end->next;
+  if ($1)
+    while ($$.end->next)
+      $$.end = $$.end->next;
+}
+ ;
+
+cmds_int: cmd_prep
+ | cmds_int cmd_prep {
+  if (!$1.begin)
+    $$ = $2;
+  else if (!$2.begin)
+    $$ = $1;
+  else {
+    $$.begin = $1.begin;
+    $$.end = $2.end;
+    $1.end->next = $2.begin;
   }
- | cmds_int cmd {
-  $$.begin = $1.begin;
-  $1.end->next = $2;
-  $$.end = $2;
-  while ($$.end->next)
-    $$.end = $$.end->next;
  }
  ;
 
index 09a4a88add5e3420f2c89834b05c7d0b986998dd..b1342819686dc3f3fd4d84c5d8ba98c31fc67dca 100644 (file)
@@ -1178,6 +1178,10 @@ bt_test_suite(t_include, "Testing including another config file");
 function t_if_else()
 int i;
 {
+       /* Empty blocks regression test */
+       if true then {}
+       else {}
+
        if true then
                bt_assert(true);
 
@@ -1187,6 +1191,10 @@ int i;
                bt_assert(true);
        else
                bt_assert(false);
+
+       /* Empty blocks regression test */
+       if true then {}
+       else {}
 }
 
 bt_test_suite(t_if_else, "Testing if-else statement");