`mpz_set_d' causes segmentation faults on parameters less than 2^-32.
KAMADA Makoto
m_kamada at nifty.com
Tue May 30 10:57:44 CEST 2006
Hello,
`mpz_set_d' causes segmentation faults on parameters less than 2^-32.
I'm not sure that this problem is restricted to my PC.
It might be a compiler's problem.
* The GMP version number, and if pre-packaged or patched then say so.
The GMP version number is 4.2.1.
I got it from http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.1.tar.gz.
I did not use any patches.
* A test program that makes it possible for us to reproduce the bug. Include instructions on how to run the program.
The test program `test.c' is here:
----------------8<----------------8<----------------8<----------------
#include <stdio.h>
#include <gmp.h>
int main() {
union {
double d;
unsigned char c[8];
} x;
mpz_t a;
mpz_init(a);
printf("gmp_version = %s\n", gmp_version);
x.d = 2.3283064365386963e-10; //x.d == 2^-32
printf("x.d = %.17g\n", x.d);
printf("x.c = %02x %02x %02x %02x %02x %02x %02x %02x\n",
x.c[0], x.c[1], x.c[2], x.c[3], x.c[4], x.c[5], x.c[6], x.c[7]);
mpz_set_d(a, x.d);
printf("ok\n");
x.d = 2.328306436538696e-10; //x.d < 2^-32
printf("x.d = %.17g\n", x.d);
printf("x.c = %02x %02x %02x %02x %02x %02x %02x %02x\n",
x.c[0], x.c[1], x.c[2], x.c[3], x.c[4], x.c[5], x.c[6], x.c[7]);
mpz_set_d(a, x.d);
printf("ok\n");
return 0;
}
----------------8<----------------8<----------------8<----------------
I got the following results:
----------------8<----------------8<----------------8<----------------
~/factorize/ggnfs6/10009_114a> gcc -Wall -o test test.c -lgmp
~/factorize/ggnfs6/10009_114a> ./test
gmp_version = 4.2.1
x.d = 2.3283064365386963e-10
x.c = 00 00 00 00 00 00 f0 3d
ok
x.d = 2.328306436538696e-10
x.c = ff ff ff ff ff ff ef 3d
5 [main] test 3764 _cygtls::handle_exceptions: Error while dumping state (
probably corrupted stack)
Segmentation fault (core dumped)
----------------8<----------------8<----------------8<----------------
* A description of what is wrong. If the results are incorrect, in what way. If you get a crash, say so.
`mpz_set_d' at line 15 makes no problems, but
`mpz_set_d' at line 21 caused a segmentation fault.
It means that 2^-32 is ok, but 2^-32-2^-85 is not ok.
* If you get a crash, include a stack backtrace from the debugger if it's informative (`where' in gdb, or `$C' in adb).
----------------8<----------------8<----------------8<----------------
~/factorize/ggnfs6/10009_114a> gdb ./test
GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"...(no debugging symbols found)
(gdb) run
Starting program: /home/makoto/factorize/ggnfs6/10009_114a/test.exe
gmp_version = 4.2.1
x.d = 2.3283064365386963e-10
x.c = 00 00 00 00 00 00 f0 3d
ok
x.d = 2.328306436538696e-10
x.c = ff ff ff ff ff ff ef 3d
Program received signal SIGSEGV, Segmentation fault.
0x0040124d in __gmpz_set_d ()
(gdb) where
#0 0x0040124d in __gmpz_set_d ()
#1 0x0022edd0 in ?? ()
#2 0xffffffff in ?? ()
#3 0x3defffff in ?? ()
#4 0x610deb48 in vfprintf () from /usr/bin/cygwin1.dll
Cannot access memory at address 0x3defffff
(gdb)
----------------8<----------------8<----------------8<----------------
* Please do not send core dumps, executables or straces.
* The configuration options you used when building GMP, if any.
I used no configuration options.
`./configure', `make', `make check' and `make install', that's all.
`make check' reported all tests passed.
* The name of the compiler and its version. For gcc, get the version with `gcc -v', otherwise perhaps `what `which cc`', or similar.
----------------8<----------------8<----------------8<----------------
~/factorize/ggnfs6/10009_114a> gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr --
exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --man
dir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,
java,objc --enable-nls --without-included-gettext --enable-version-specific-runt
ime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --ena
ble-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=b
oehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchroniza
tion --enable-libstdcxx-debug : (reconfigured)
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
----------------8<----------------8<----------------8<----------------
* The output from running `uname -a'.
----------------8<----------------8<----------------8<----------------
~/gmp-4.2.1> uname -a
CYGWIN_NT-5.1 RIKA 1.5.19(0.150/4/2) 2006-01-20 13:28 i686 Cygwin
----------------8<----------------8<----------------8<----------------
* The output from running `./config.guess', and from running `./configfsf.guess' (might be the same).
----------------8<----------------8<----------------8<----------------
~/gmp-4.2.1> ./config.guess
pentium4-pc-cygwin
~/gmp-4.2.1> ./configfsf.guess
i686-pc-cygwin
----------------8<----------------8<----------------8<----------------
* If the bug is related to `configure', then the contents of config.log.
* If the bug is related to an asm file not assembling, then the contents of config.m4 and the offending line or lines from the temporary mpn/tmp-<file>.s.
[END OF REPORT]
Makoto Kamada
More information about the gmp-bugs
mailing list