Skip to content

Commit

Permalink
ielr: fix crash on memory management
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akimd committed Jun 26, 2020
1 parent 8f44164 commit f6dd943
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Di-an Jan dianj@freeshell.org
Dick Streefland dick.streefland@altium.nl
Didier Godefroy dg@ulysium.net
Don Macpherson donmac703@gmail.com
Dwight Guth dwight.guth@runtimeverification.com
Efi Fogel efifogel@gmail.com
Enrico Scholz enrico.scholz@informatik.tu-chemnitz.de
Eric Blake ebb9@byu.net
Expand Down
4 changes: 3 additions & 1 deletion src/AnnotationList.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -309,6 +310,7 @@ AnnotationList__computePredecessorAnnotations (
predecessor_item);
}
}
after_sbitset__for_each:;
}
if (annotation_node->contributions[ci])
{
Expand Down
2 changes: 2 additions & 0 deletions src/Sbitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down

0 comments on commit f6dd943

Please sign in to comment.