bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

segfault in mpz_powm with big mod on CYGWIN


From: Washuu Kobayashi
Subject: segfault in mpz_powm with big mod on CYGWIN
Date: Mon, 28 Mar 2005 11:38:51 +0200

Hello,

on  all  machines with up-to-date CYGWIN installed, the following code
causes segmentation fault.

#include <stdio.h>
#include <gmp.h>

int main (){
printf ("Start!\n");
mpz_t M,Mm1,y,c;
mpz_init(M);
mpz_init(Mm1);
mpz_init(y);
mpz_init_set_ui(c,30L);
mpz_ui_pow_ui(M,2L,2380000L);
mpz_sub_ui(Mm1,M,1L);
printf ("Mult OK!\n"); //we get this message
mpz_powm(y,c,c,Mm1);
printf ("Pow OK!\n"); //but we won't get this one
return 0;
}

The program try to compute (30^30)%(2^2,380,000-1), which is of course
30^30, but it crashes with segmentation fault, probably because of bug
in memory allocation code. (But 2^2,380,000 is correctly calculated!).

The bug does NOT exist on another systems, such as linux.

BTW:  it  seems strange for me that GMP complains about lack of memory
in  some cases. For example: mpz_powm(K,L,M) closes program when K,L,M
are  like  10^10,000,000  (so  each variable should take about 10MB of
memory or less). If I understand powering modulo, the maximum value of
temporary  integer is K*M=10^20,000,000, because it always get reduced
to  0..M-1  after  multiplication (so 20 MB more). I have 1GB RAM, and
GMP cannot handle such situations...

-- 
Best regards,
 Washuu                          mailto:address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]