bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bitset: check memory allocation


From: Paul Eggert
Subject: Re: bitset: check memory allocation
Date: Thu, 5 Sep 2019 13:54:35 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 9/5/19 12:59 PM, Akim Demaille wrote:

            EBITSET_ELTS (src)
-            = realloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *));
+            = xrealloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *));

This code is trying to shrink the bitset, and in the unlikely event that such an attempt fails there's no need call xrealloc which will exit the whole program; the code can continue to call realloc and if that fails, the code can forge ahead with the unshrunk bitset.

There's a similar issue in the vector.c patch.

Other than that, looks OK to me; as I understand it the bitset code is not intended for libraries (as lib/bitset/stats.c already calls xcalloc, and OBSTACK_CHUNK_ALLOC and OBSTACK_CHUNK_FREE default to xmalloc and free) so it's OK for it to call xrealloc.

Come to think of it, though, what's the intent of OBSTACK_CHUNK_ALLOC and OBSTACK_CHUNK_FREE? If the intent is for the builder to replace xmalloc and free, shouldn't the including code also be able to redefine xrealloc and xrealloc?

Also, a nit in nearby code: xcalloc (1, N) is better written as xzalloc (N).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]