Re: [PATCH 2/4] reftable: fix allocation count on realloc error
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 27, 2024, 20:16 UTC
- Message-ID
- <68bd4e99-ed59-443a-a3c5-bb06653cfad5@web.de>
- In-Reply-To
- <Z26ClnvVH1cg3CGQ@pks.im>
Am 27.12.24 um 11:33 schrieb Patrick Steinhardt:
Show 10 quoted lines
> On Wed, Dec 25, 2024 at 07:38:35PM +0100, René Scharfe wrote: > >> diff --git a/reftable/basics.h b/reftable/basics.h >> index 259f4c274c..fa5d75868b 100644 >> --- a/reftable/basics.h >> +++ b/reftable/basics.h >> @@ -120,22 +120,35 @@ char *reftable_strdup(const char *str); >> #define REFTABLE_ALLOC_ARRAY(x, alloc) (x) = reftable_malloc(st_mult(sizeof(*(x)), (alloc))) >> #define REFTABLE_CALLOC_ARRAY(x, alloc) (x) = reftable_calloc((alloc), sizeof(*(x))) >> #define REFTABLE_REALLOC_ARRAY(x, alloc) (x) = reftable_realloc((x), st_mult(sizeof(*(x)), (alloc)))
Show 9 quoted lines
>> +#define REFTABLE_ALLOC_GROW(x, nr, alloc) ( \ >> + (nr) > (alloc) && ( \ >> + (x) = reftable_alloc_grow((x), (nr), sizeof(*(x)), &(alloc)), \ >> + (nr) > (alloc) \ >> + ) \ >> +) > > Do we even need this macro? I don't really think it serves much of a > purpose anymore.
It provides the same value as the *ALLOC_ARRAY macros above: automatic sizeof handling. Plus it returns whether the allocation succeeded, avoiding repetition of its arguments in callers.
René