[PATCH 4/4] ielr: fix crash on memory management

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.bugs
Message-ID <[email protected]>
Reported by Dwight Guth.
https://lists.gnu.org/r/bug-bison/2020-06/msg00037.html

* src/AnnotationList.c (AnnotationList__computePredecessorAnnotations):
Beware that SBITSET__FOR_EACH nests _two_ for-loops, so "break" does
not actually break out of it.
That was the only occurrence in the code.
* src/Sbitset.h (SBITSET__FOR_EACH): Warn passersby.
---
 THANKS               | 1 +
 src/AnnotationList.c | 4 +++-
 src/Sbitset.h        | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/THANKS b/THANKS
index 36df5e29..af24ceaa 100644
--- a/THANKS
+++ b/THANKS
@@ -59,6 +59,7 @@ Di-an Jan                 [email protected]
 Dick Streefland           [email protected]
 Didier Godefroy           [email protected]
 Don Macpherson            [email protected]
+Dwight Guth               [email protected]
 Efi Fogel                 [email protected]
 Enrico Scholz             [email protected]
 Eric Blake                [email protected]
diff --git a/src/AnnotationList.c b/src/AnnotationList.c
index a95a67be..421643b2 100644
--- a/src/AnnotationList.c
+++ b/src/AnnotationList.c
@@ -276,7 +276,8 @@ AnnotationList__computePredecessorAnnotations (
                         obstack_free (annotations_obstackp,
                                       annotation_node->contributions[ci]);
                         annotation_node->contributions[ci] = NULL;
-                        break;
+                        // "Break" out of SBITSET__FOR_EACH.
+                        goto after_sbitset__for_each;
                       }
                     else
                       {
@@ -309,6 +310,7 @@ AnnotationList__computePredecessorAnnotations (
                                     predecessor_item);
                   }
               }
+          after_sbitset__for_each:;
           }
           if (annotation_node->contributions[ci])
             {
diff --git a/src/Sbitset.h b/src/Sbitset.h
index 997dab2f..c54def4e 100644
--- a/src/Sbitset.h
+++ b/src/Sbitset.h
@@ -81,6 +81,8 @@ void Sbitset__fprint (Sbitset self, Sbitset__Index nbits, FILE *file);
       *ptr_self = *ptr_other1 | *ptr_other2;                            \
   } while (0)
 
+/* ATTENTION: there are *two* loops here, "break" and "continue" will
+   not apply to the whole loop, just the inner one.  */
 # define SBITSET__FOR_EACH(SELF, NBITS, ITER, INDEX)                    \
   for ((ITER) = (SELF); (ITER) < (SELF) + Sbitset__nbytes (NBITS); ++(ITER)) \
     if (*(ITER) != 0)                                                   \
-- 
2.27.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.