integer overflow in mini-gmp due to integer promotion

Niels Möller nisse at lysator.liu.se
Wed Jul 19 22:08:24 CEST 2023


Vincent Lefevre <vincent at vinc17.net> writes:

> On 2023-07-19 21:24:03 +0200, Niels Möller wrote:
>> I think that's needed, to be able to support any size of
>> MINI_GMP_LIMB_TYPE. Something like
>> 
>> #define umullo_limb(u, v) \
>>   (sizeof(mp_limb_t) >= sizeof(int)) ? (u)*(v) : (unsigned int)(u) * (v))
>> 
>> If I understand you correctly, the two multiplies in
>> gmp_udiv_qrnnd_preinv and gmp_udiv_qr_3by2 are the only places where we
>> need a mullo operation, i.e., producing the low limb of a limb product?
>
> These are the only ones that affect MPFR, but I haven't looked
> at the whole code.

Can you try out the attached patch?

Regards,
/Niels

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mini-gmp-umullo.patch
Type: text/x-diff
Size: 1396 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20230719/b6bdcb00/attachment.bin>
-------------- next part --------------

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-bugs mailing list