Re: Problem with gmp_randinit_set

2017-02-13 Thread Torbjörn Granlund

   gmp_randinit_set(b, a);
   gmp_randseed_ui(b, 123456); /* crashes */
  
  AFAICT this is a gmp bug, but I don't rule out the possibility that
  it's a user bug.
  
This looks like a GMP bug.

I never looked properly through the GMP PRNG code, and looking at it now
I don't immediately understand its structure.  (This code was written by
an external contributor.)

What happens with your code is that GMP tries to call a seed application
function through a pointer, but that pointer was explicitly zeroed by
gmp_randinit_set (or in __gmp_randiset_mt to be exact).

One can change Mersenne_Twister_Generator_Noseed to
Mersenne_Twister_Generator to fix this (and move __gmp_randiset_mt to
randmts.c as mandated by Mersenne_Twister_Generator's scope), and then
your code supposedly runs without a crash.  But I don't see why one ever
wants Mersenne_Twister_Generator_Noseed, which suggests my understanding
of this code is very poor indeed.

-- 
Torbjörn
Please encrypt, key id 0xC8601622
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Problem with gmp_randinit_set

2017-02-13 Thread sisyphus1

Hi,

The following program crashes for me on MS Windows 7, gmp-6.1.2, when the 
line "gmp_randseed_ui(b, 123456);" is executed.
I built gmp in the MSYS2 shell using gcc version 5.3.0 
(x86_64-posix-sjlj-rev0, Built by MinGW-W64 project).


Configure command was:

./configure 
CC="gcc -D__USE_MINGW_ANSI_STDIO" --enable-static --disable-shared --enable-assembly 
LDFLAGS=-LC:/_64/msys_530/1.0/local/lib 
CPPFLAGS=-IC:/_64/msys_530/1.0/local/include --prefix=C:/_64/msys_530/1.0/local


/*/
#include 
#include 

int main(void) {
 gmp_randstate_t a, b;
 gmp_randinit_default(a);
 /* gmp_randseed_ui(a, 123456); *//* same result with or without this line 
*/

 gmp_randinit_set(b, a);
 /* printf("%s\n", gmp_version); *//* outputs 6.1.2 */
 gmp_randseed_ui(b, 123456); /* crashes */

 return 0;
}

//

AFAICT this is a gmp bug, but I don't rule out the possibility that it's a 
user bug.


If "a" is initialised with either gmp_randinit_lc_2exp() or 
gmp_randinit_lc_2exp_size() there is no crash.


Cheers,
Rob 


___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs