undefined behavior in GMP 5.1.2

Vincent Lefevre vincent at vinc17.net
Mon Sep 23 15:43:15 CEST 2013

On 2013-09-23 14:36:24 +0200, Marc Glisse wrote:
> On Mon, 23 Sep 2013, Vincent Lefevre wrote:
> >Sorry, I looked at a wrong test. The problem is due to the mpf_pow_ui
> >test with a large exponent. Something like the attached patch should
> >solve the problem (in2i is reduced for this function).
> Thanks for the analysis and the patch! It is funny how I can reproduce it
> running ./reuse by hand but it doesn't show during a make check, maybe the
> random seed...

Yes, without -fno-sanitize-recover, I get only 2 failing tests over
the 10000, when run by hand. Even if I do in2i /= EXPO, I still get
a failing test, when run by hand.

On 2013-09-23 15:18:38 +0200, Niels Möller wrote:
> Marc Glisse <marc.glisse at inria.fr> writes:
> > I'll apply it if I don't hear from anyone else.
> It would be nice with a comment explaining the problem, i.e., why the
> size of in2i must be restricted. I guess the intention is to avoid that
> the mpf exponent gets out of range, or is it something more subtle?

in1 has a maximum exponent EXPO in absolute value.
With in2i /= 2 * EXPO, the power in2i multiplied by the exponent
of in1 is around at most MP_LIMB_T_MAX / 2 in absolute value. The
factor 2 may not be enough in some uncommon cases, but a factor 4
would be OK.

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

More information about the gmp-bugs mailing list