integer overflow in mini-gmp due to integer promotion

Vincent Lefevre vincent at vinc17.net
Thu Jul 20 05:58:47 CEST 2023


On 2023-07-19 22:08:24 +0200, Niels Möller wrote:
> 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?

No problems when testing MPFR with MINI_GMP_LIMB_TYPE = long, int,
short and char, with -m64 and with -m32.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-bugs mailing list