Reported by 江 祖铭 (Zu-Ming Jiang).
With help from Paul Eggert.
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00016.html
* lib/bitset/table.c (tbitset_resize): When growing, use xrealloc
instead of realloc.
When shrinking, accept failures.
* lib/bitset/vector.c (vbitset_resize): Likewise.
+2019-09-06 Akim Demaille <akim@lrde.epita.fr>
+
+ bitset: check memory allocation
+ Reported by 江 祖铭 (Zu-Ming Jiang).
+ With help from Paul Eggert.
+ https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00016.html
+ * lib/bitset/table.c (tbitset_resize): When growing, use xrealloc
+ instead of realloc.
+ When shrinking, accept failures.
+ * lib/bitset/vector.c (vbitset_resize): Likewise.
+
2019-09-07 Paul Eggert <eggert@cs.ucla.edu>
scratch_buffer: sync from glibc
#include <string.h>
#include "obstack.h"
+#include "xalloc.h"
/* This file implements expandable bitsets. These bitsets can be of
arbitrary length and are more efficient than arrays of bits for
bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4;
EBITSET_ELTS (src)
- = realloc (EBITSET_ELTS (src), size * sizeof (tbitset_elt *));
+ = xrealloc (EBITSET_ELTS (src), size * sizeof (tbitset_elt *));
EBITSET_ASIZE (src) = size;
}
the memory unless it is shrinking by a reasonable amount. */
if ((oldsize - newsize) >= oldsize / 2)
{
- EBITSET_ELTS (src)
+ void *p
= realloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *));
- EBITSET_ASIZE (src) = newsize;
+ if (p)
+ {
+ EBITSET_ELTS (src) = p;
+ EBITSET_ASIZE (src) = newsize;
+ }
}
/* Need to prune any excess bits. FIXME. */
#include <stdlib.h>
#include <string.h>
+#include "xalloc.h"
+
/* This file implements variable size bitsets stored as a variable
length array of words. Any unused bits in the last word must be
zero.
bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4;
VBITSET_WORDS (src)
- = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word));
+ = xrealloc (VBITSET_WORDS (src), size * sizeof (bitset_word));
VBITSET_ASIZE (src) = size;
}
the memory unless it is shrinking by a reasonable amount. */
if ((oldsize - newsize) >= oldsize / 2)
{
- VBITSET_WORDS (src)
+ void *p
= realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word));
- VBITSET_ASIZE (src) = newsize;
+ if (p)
+ {
+ VBITSET_WORDS (src) = p;
+ VBITSET_ASIZE (src) = newsize;
+ }
}
/* Need to prune any excess bits. FIXME. */