bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* bitset: check memory allocation
@ 2019-09-05 19:59 Akim Demaille
  2019-09-05 20:54 ` Paul Eggert
  0 siblings, 1 reply; 5+ messages in thread
From: Akim Demaille @ 2019-09-05 19:59 UTC (permalink / raw)
  To: Gnulib bugs

Hi!

Ok to push?

commit 1fddc3eddd988829cd2b5b74dc3fab58a3093af8
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Thu Sep 5 11:36:39 2019 +0200

    bitset: check memory allocation
    
    Reported by 江 祖铭 (Zu-Ming Jiang).
    https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00016.html
    
    * lib/bitset/table.c (tbitset_resize): Use xrealloc instead of
    realloc.
    * lib/bitset/vector.c (vbitset_resize): Likewise.

diff --git a/lib/bitset/table.c b/lib/bitset/table.c
index 07184d657..01bc65167 100644
--- a/lib/bitset/table.c
+++ b/lib/bitset/table.c
@@ -25,6 +25,7 @@
 #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
@@ -142,7 +143,7 @@ tbitset_resize (bitset src, bitset_bindex n_bits)
 
           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;
         }
 
@@ -156,7 +157,7 @@ tbitset_resize (bitset src, bitset_bindex n_bits)
       if ((oldsize - newsize) >= oldsize / 2)
         {
           EBITSET_ELTS (src)
-            = realloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *));
+            = xrealloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *));
           EBITSET_ASIZE (src) = newsize;
         }
 
diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c
index 54f148d56..11960bbd0 100644
--- a/lib/bitset/vector.c
+++ b/lib/bitset/vector.c
@@ -24,6 +24,8 @@
 #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.
@@ -74,7 +76,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits)
 
           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;
         }
 
@@ -89,7 +91,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits)
       if ((oldsize - newsize) >= oldsize / 2)
         {
           VBITSET_WORDS (src)
-            = realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word));
+            = xrealloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word));
           VBITSET_ASIZE (src) = newsize;
         }
 



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-09-08  6:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05 19:59 bitset: check memory allocation Akim Demaille
2019-09-05 20:54 ` Paul Eggert
2019-09-07  5:58   ` Akim Demaille
2019-09-08  1:17     ` Paul Eggert
2019-09-08  6:43       ` Akim Demaille

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).