GMP crashes when converting large number to char *

Wee Jin Goh wjgoh at
Sat Jan 21 19:23:05 CET 2006


I think I may have found a bug with GMP when working with very large
numbers. The following source code demonstrates the problem:

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

int main(void)
	mpz_t res;
	clock_t start, end;
	start = clock();
	mpz_ui_pow_ui(res, 12345678, 1234567);
	end = clock();
	printf("Time taken is %2.5lf seconds\n", (double)(end -
	gmp_printf("The result is %Zd\n", res);
	return 0;

When you compile and run the program, it crashes at gmp_printf. Here are
the relevant details of my setup:

gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)
gmp-4.1.4 (configured with --enable-cxx)
Linux tomas 2.6.12-10-686 #1 Mon Jan 16 17:58:04 UTC 2006 i686 GNU/Linux

Output from gdb:

> (gdb) run
> Starting program: /home/wjgoh/My Downloads/test
> Time taken is 5.39000 seconds
> Program received signal SIGSEGV, Segmentation fault.
> 0xb7edbb51 in __gmpn_tdiv_qr (qp=0xbf6fac30, rp=0xbf51c660, qxn=0,
>     np=0xbf8941f0, nn=Variable "nn" is not available.
> ) at tdiv_qr.c:250
> 250                     mpn_lshift (d2p, dp + in, qn, cnt);

Hope this is enough information to help you find the bug. If you need
any more information I will be happy to assist in any way I can.


More information about the gmp-bugs mailing list