Bug involving GMP and mpz_urandomb

Perry Lee perrylee_2004 at yahoo.com
Sun Dec 23 20:06:15 CET 2012


Hello,

I believe that I've found a bug involving the GMP library (though I suspect it could just be the compiler?).
I'm running Windows XP with MinGW GCC 4.7.2,  and I compiled using the MSYS shell.
My CPU is an Intel Atom N270.
The version of I'm using is GMP 5.1.0 (the unmodified source from the release version), configured with

./configure --enable-cxx --enable-fat --disable-shared --enable-static --with-gnu-ld

'make check' passed all of the tests.


When I run this code:

#include <gmp.h>
int main(void)
{
  gmp_randstate_t rs;
  mpz_t randNum;
  gmp_randinit_default(rs);
  int i;
  for (i = 0; i < 1; ++i) /* the "1" can be any number, really */
    mpz_urandomb(randNum, rs, 32);
  gmp_randclear(rs);
  return 0;
}

(compiled with gcc -g test.c -lgmp -o test.exe, where "test.c" is the name of the file containing this code)
I get a crash on the line "mpz_urandomb(randNum, rs, 32);", as shown by this GDB backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x00402dd0 in __gmp_randget_mt ()
(gdb) bt full
#0  0x00402dd0 in __gmp_randget_mt ()
No symbol table info available.
#1  0x0040144c in __gmpz_urandomb ()
No symbol table info available.
#2  0x004013f0 in main () at test.c:9
        rs = {{_mp_seed = {{_mp_alloc = 625, _mp_size = 4358142,
                _mp_d = 0x3e42d0}}, _mp_alg = (unknown: 1), _mp_algdata = {
              _mp_lc = 0x42a064}}}
        randNum = {{_mp_alloc = 2009288233, _mp_size = 2009288258,
            _mp_d = 0x427fa0 <__do_global_dtors>}}
        i = 0

The interesting part is that if I remove the loop (the line "for (i = 0; i < 1; ++i)" ), then the program runs normally, without crashing, which leads me to suspect that this could be a compiler problem (the loop only runs once in the test code, so the effect should be the exact same, right?).
Unfortunately, due to the rather large amount of time it takes for me to compile GMP on my computer, I haven't had the opportunity to test this with an earlier version of MinGW GCC, an earlier version of GMP, or GMP with any of the debug options. (if you'd like, I can recompile with one of those to see if it still crashes)

Here's some info about my system:

The output of 'gcc -v':
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-
with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.2 (GCC)

The output of 'uname -a':
MINGW32_NT-5.1 EMACHINE-97610C 1.0.18(0.48/3/2) 2012-11-21 22:34 i686 Msys

The output of './config.guess':
atom-pc-mingw32

The output of './configfsf.guess':
i686-pc-mingw32

If you need any other information, feel free to ask.

Thanks!


More information about the gmp-bugs mailing list