[PATCH] mini-gmp: pass correct old_size to custom reallocate function
Marco Bodrato
bodrato at mail.dm.unipi.it
Mon Mar 9 10:23:44 UTC 2020
Ciao,
Il 2020-03-07 21:27 minux ha scritto:
> All comments addressed, except as noted below.
> I also fixed similar issues in mini-mpq.c changes.
>
> On Sat, Mar 7, 2020 at 2:26 PM Niels Möller <nisse at lysator.liu.se>
> wrote:
>> minux <minux.ma at gmail.com> writes:
>> I'm not that familiar with the mpq functions. I hope Marco can
>> comment.
I had problems with my e-mail adress, but I'm here again :-)
Maybe there are some unneeded initialisations = NULL, but details can
also be refined later...
There is an undocumented "feature" that the proposed patch breaks:
"safe" failure when the base is out of range.
The question is, should we keep it or not, document it or not, should
GMP and mini-gmp agree?
I attach a possible patch for tests that check that feature.
>> > @@ -4199,7 +4208,7 @@
>> > - size_t i, sn;
>> > + size_t i, sn, osn = 0;
>> > @@ -4220,15 +4229,15 @@
>> > if (!sp)
>> > - sp = (char *) gmp_xalloc (1 + sn);
>> > + sp = (char *) gmp_xalloc (osn = 1 + sn);
>>
>> I'd prefer
>>
>> if (!sp)
>> {
>> osn = 1 + sn;
>> sp = (char *) gmp_xalloc (osn);
>> }
>> else
>> osn = 0;
>>
>> (and drop the zero initialization at the declaration above).
There are many other places where we initialize a variable with a
"default" and we conditionally change the value... I agree with the
separate line for "osn = 1 + sn".
For the style, I do not know which one is better:
"if(c){v=val}else{v=0};" or "v=0;if(c){v=val};"
Ĝis,
m
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mpz_get_str_tests.patch
Type: text/x-diff
Size: 2170 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20200309/80659b8f/attachment.bin>
More information about the gmp-devel
mailing list