Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong fix for #72 #74

Closed
bazsi opened this issue Feb 11, 2021 · 4 comments
Closed

Wrong fix for #72 #74

bazsi opened this issue Feb 11, 2021 · 4 comments

Comments

@bazsi
Copy link

bazsi commented Feb 11, 2021

Hi,

As it seems the fix for #72 was not entirely successful. The bitset is not properly shifted to the right. See this patch:

diff --git a/src/tables.c b/src/tables.c
index b04a496e..60e3ec93 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -186,8 +186,8 @@ pos_set_set (int pos)
       bitset_resize (pos_set, new_size);
       // Shift all the bits by DELTA.
       // FIXME: add bitset_assign, and bitset_shift?
-      for (int i = new_size - 1; delta <= i ; --i)
-        if (bitset_test (pos_set, i))
+      for (int i = old_size - 1; i >= -delta ; --i)
+        if (i >= 0 && bitset_test (pos_set, i))
           bitset_set (pos_set, i + delta);
         else
           bitset_reset (pos_set, i + delta);

With this patch in place, the generated grammars work for me.

@bazsi
Copy link
Author

bazsi commented Mar 4, 2021

@akimd can you check if this patch is sufficient?
thanks

@akimd
Copy link
Owner

akimd commented Mar 7, 2021

Hi @bazsi
Sorry for the delays. Yes, you are right, my fix was wrong on several accounts... I will install the following patch. This deserves a new release.

commit b426de59c284cd512b1ec974ac39f4fdbd0d3f21
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sun Mar 7 08:19:36 2021 +0100

    tables: fix again the handling for useless tokens
    
    The right-shift added in c22902e360e0fbbe9fd5657dcf107e03166da309
    ("tables: fix handling for useless tokens") is incorrect.  In
    particular, we need to reset the "new" bits.
    
    Reported by Balázs Scheidler.
    https://github.com/akimd/bison/issues/74
    
    * src/tables.c (pos_set_set): Fix the right-shift.

diff --git a/src/tables.c b/src/tables.c
index 6c8fc1cc6..a0f7cb365 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -180,21 +180,26 @@ pos_set_set (int pos)
   int bitno = pos - pos_set_base;
   if (bitno < 0)
     {
+      // Need more room on the left.
+      // DELTA is positive.  Run 'bitset >> delta'.
       const int delta = pos_set_base - pos;
       const int old_size = bitset_size (pos_set);
       const int new_size = old_size + delta;
       bitset_resize (pos_set, new_size);
-      // Shift all the bits by DELTA.
+      // Right-shift all the bits by DELTA.  Be sure to reset the new
+      // bits on the left.
+      //
       // FIXME: add bitset_assign, and bitset_shift?
-      for (int i = new_size - 1; delta <= i ; --i)
-        if (bitset_test (pos_set, i))
-          bitset_set (pos_set, i + delta);
+      for (int i = new_size - 1; 0 <= i ; --i)
+        if (delta <= i && bitset_test (pos_set, i - delta))
+          bitset_set (pos_set, i);
         else
-          bitset_reset (pos_set, i + delta);
+          bitset_reset (pos_set, i);
       pos_set_base = pos;
       bitno = 0;
     }
   else if (bitset_size (pos_set) <= bitno)
+    // Need more room on the right.
     bitset_resize (pos_set, bitno + 1);
   bitset_set (pos_set, bitno);
 }

akimd added a commit that referenced this issue Mar 7, 2021
The right-shift added in c22902e
("tables: fix handling for useless tokens") is incorrect.  In
particular, we need to reset the "new" bits.

Reported by Balázs Scheidler.
#74

* src/tables.c (pos_set_set): Fix the right-shift.
akimd added a commit that referenced this issue Mar 7, 2021
The right-shift added in c22902e
("tables: fix handling for useless tokens") is incorrect.  In
particular, we need to reset the "new" bits.

Reported by Balázs Scheidler.
#74

* src/tables.c (pos_set_set): Fix the right-shift.
akimd added a commit that referenced this issue Mar 7, 2021
The right-shift added in c22902e
("tables: fix handling for useless tokens") is incorrect.  In
particular, we need to reset the "new" bits.

Reported by Balázs Scheidler.
#74

* src/tables.c (pos_set_set): Fix the right-shift.
akimd added a commit that referenced this issue Mar 7, 2021
The right-shift added in c22902e
("tables: fix handling for useless tokens") is incorrect.  In
particular, we need to reset the "new" bits.

Reported by Balázs Scheidler.
#74

* src/tables.c (pos_set_set): Fix the right-shift.
@akimd
Copy link
Owner

akimd commented Mar 10, 2021

Fixed in 3.7.6. Thanks for the report Balázs, and sorry about this.

@akimd akimd closed this as completed Mar 10, 2021
@bazsi
Copy link
Author

bazsi commented Mar 10, 2021 via email

gaborznagy pushed a commit to gaborznagy/syslog-ng that referenced this issue Apr 23, 2021
bison minimum version had to be updated to version 3.7.6 (see reasons in [1], [2])
bison installation from source tarball was introduced in [3]

We decided that platforms except the `syslog-ng-tarball` image must build syslog-ng from tarball.
`syslog-ng-kira` image should be added as another exception, so Kira-syslog-ng can build syslog-ng from source as well.

[1] akimd/bison#74
[2] akimd/bison#72
[3] syslog-ng#3588

Signed-off-by: Gabor Nagy <gabor.nagy@oneidentity.com>
bazsi pushed a commit to bazsi/syslog-ng that referenced this issue Apr 29, 2021
bison minimum version had to be updated to version 3.7.6 (see reasons in [1], [2])
bison installation from source tarball was introduced in [3]

We decided that platforms except the `syslog-ng-tarball` image must build syslog-ng from tarball.
`syslog-ng-kira` image should be added as another exception, so Kira-syslog-ng can build syslog-ng from source as well.

[1] akimd/bison#74
[2] akimd/bison#72
[3] syslog-ng#3588

Signed-off-by: Gabor Nagy <gabor.nagy@oneidentity.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants