[PATCH] mini-gmp: pass correct old_size to custom reallocate function

Niels Möller nisse at lysator.liu.se
Thu Mar 12 19:19:05 UTC 2020


minux <minux.ma at gmail.com> writes:

> Indeed, this is much simpler and avoids the risk of calling
> strlen(NULL). Thanks.
>
> Patch updated. Please take another look.

Looks good to me. I was about to submit, but then I have one minor
question about naming.

>  #define gmp_xalloc(size) ((*gmp_allocate_func)((size)))
> -#define gmp_free(p) ((*gmp_free_func) ((p), 0))
> +#define gmp_xfree(p, size) ((*gmp_free_func) ((p), (size)))
> +#define gmp_xrealloc(ptr, old_size, size) ((*gmp_reallocate_func)(ptr, old_size, size))

Here, "xalloc" is the traditional name (at least in GNU code, another
name is xmalloc) for an allocation function that will crash with an
error message on failure, rather than returning NULL. The name
gmp_xalloc in mini-gmp most likely dates from before support for
get_set_memory_functions was added, and then it did the same thing as
the current gmp_default_alloc, with no indirection.

The xrealloc function is analogous (but maybe not as widely used as
xalloc). On the other hand, I don't know of any traditional function
named xfree. So maybe the least confusing naming is to strike "x" from
all the names (six in all, including the _limbs variants)?

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list