Bug Report GMP-5.1.1 Mini-gmp t-double.c
Niels Möller
nisse at lysator.liu.se
Mon Feb 25 16:04:50 CET 2013
Michael Tate <michael.tate at wanadoo.fr> writes:
> Hello, I have come across a possible failure in the mini-gmp test suite and
> have decided to submit a report.
There were two problems. The memory "clobbered before allocated block"
was due to testcode doing
char *buf = mpz_get_str (NULL, 16, x);
fprintf (stderr, "%s: %s\n", label, buf);
free (buf);
This code is incorrect, if mp_set_memory_functions has been used to
install some allocation functions incompatible with free, something the
mini-gmp testsuite does. I have checked in a fix for this.
Then, the actual problem, I think, is similar to the recently discussed
problem with the main gmp testsuite on m68k. The mini-gmp test
does
f = d + 1.0;
if (f > d) ...
Now, the problem is that the addition and comparison is done with
extended precision (I guess it's the old fashioned 387 floating point
unit registers), and then f > d, but after truncating to double
precision, we get f == d.
The below patch, using volatile to force values into memory (in double
precision) and back seems to solve the problem. I'll check this in soon,
unless I get some better suggestion. For mini-gmp, using compiler
dependent tricks and command line options is highly undesirable. And as
far as I understand, volatile is a portable (although a bit ugly) way to
drop extended precision.
Regards,
/Niels
--- a/mini-gmp/tests/t-double.c Mon Feb 25 15:48:02 2013 +0100
+++ b/mini-gmp/tests/t-double.c Mon Feb 25 15:57:51 2013 +0100
@@ -83,7 +83,7 @@ testmain (int argc, char **argv)
for (i = 0; i < COUNT; i++)
{
- double d, f;
+ volatile double d, f;
unsigned long m;
int e;
--
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
More information about the gmp-bugs
mailing list