undefined behavior in GMP 5.1.2
Vincent Lefevre
vincent at vinc17.net
Mon Sep 23 13:43:41 CEST 2013
On 2013-09-23 12:49:36 +0200, Marc Glisse wrote:
> On Mon, 23 Sep 2013, Vincent Lefevre wrote:
>
> >On 2013-09-23 10:05:35 +0200, Vincent Lefevre wrote:
> >>On 2013-09-23 07:31:05 +0200, Marc Glisse wrote:
> >>>On Mon, 23 Sep 2013, Vincent Lefevre wrote:
> >>>
> >>>>On 2013-09-21 11:57:42 +0200, Marc Glisse wrote:
> >>>>>>>mul.c:81:31: runtime error: signed integer overflow:
> >>>>>>>-5260204364771764878 + -5260204364771764878 cannot be represented in
> >>>>>>>type 'long'
> >>>>>
> >>>>>We don't check for underflow in mpf multiplication, I didn't touch that.
> >>>>>People should use mpfr ;-)
[...]
> Ok, thanks. In my opinion this misplaced warning is a bug in the
> sanitizer then.
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).
--
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)
-------------- next part --------------
--- tests/mpf/reuse.c.old 2013-05-20 16:59:58.000000000 +0200
+++ tests/mpf/reuse.c 2013-09-23 13:40:23.000000000 +0200
@@ -72,6 +72,7 @@
mpf_mul_2exp, mpf_div_2exp, mpf_pow_ui
};
+/* mpf_pow_ui must be the last function */
const char *dsi_func_names[] =
{
"mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui",
@@ -152,6 +153,9 @@
if (strcmp (dsi_func_names[i], "mpf_div_ui") == 0 && in2i == 0)
continue;
+ if (strcmp (dsi_func_names[i], "mpf_pow_ui") == 0)
+ in2i /= 2 * EXPO;
+
(dsi_funcs[i]) (res1, in1, in2i);
mpf_set (out1, in1);
More information about the gmp-bugs
mailing list