[PATCH] mini-gmp: pass correct old_size to custom reallocate function
minux
minux.ma at gmail.com
Mon Mar 9 21:16:18 UTC 2020
Hello,
On Mon, Mar 9, 2020 at 8:43 AM Marco Bodrato <bodrato at mail.dm.unipi.it> wrote:
> Il 2020-03-09 13:04 minux ha scritto:
> > I added a check for out-of-range base to the beginning of mpq_get_str
>
> I'd prefer to let checking ranges outside of the mpq code.
> If res==NULL for whatever reason, goto ret is incorrect anyway: the next
> instruction is strlen(res).
>
> > Please take another look at the attached patch. All existing comments
> > addressed.
>
> If the goal of the patch is to "pass correct old_size to custom
> reallocate [and free] function[s]", I'd simply suggest the following:
>
> @@ -498,9 +498,9 @@
>
> mp_get_memory_functions (NULL, &gmp_reallocate_func,
> &gmp_free_func);
> lden = strlen (rden) + 1;
> - res = (char *) gmp_reallocate_func (res, 0, (lden + len) * sizeof
> (char));
> + res = (char *) gmp_reallocate_func (res, len * sizeof (char), (lden
> + len) * sizeof (char));
> memcpy (res + len, rden, lden);
> - gmp_free_func (rden, 0);
> + gmp_free_func (rden, lden * sizeof (char));
> }
>
> res [len - 1] = '/';
Indeed, this is much simpler and avoids the risk of calling
strlen(NULL). Thanks.
Patch updated. Please take another look.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mini-gmp.patch
Type: application/octet-stream
Size: 11537 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20200309/68b46db8/attachment-0001.obj>
More information about the gmp-devel
mailing list