[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SegFault in 2**111111111 calculation
From: |
Pearu Peterson |
Subject: |
SegFault in 2**111111111 calculation |
Date: |
Wed, 6 Dec 2000 20:02:42 +0200 (GMT-2) |
Hi,
I am using the latest GMP 3.1 on
Linux 2.2.14-15mdk i686
with
gcc version 2.95.2 19991024 (release)
GMP is configured and installed with default compiler flags (-g -O
-fomit-frame-pointer -mcpu=pentiumpro). make check was success.
ulimit is 'unlimited'. Tried also --disable-alloc for the test below.
Now, I have found that when trying to find the power over a huge
exponent (but still in the range of unsigned long) then Segmentation Fault
is raised. The test code is given below that calculates BA**EX.
If BA=2,EX=11, for example, then the output is
Calculating 2**11:
mp_allocate( 4 ) ->0x8049b60
sizein10(2**11)=4
But if EX=111111111 then
Calculating 2**111111111:
mp_allocate( 4 ) ->0x8049b80
Segmentation fault
Is this a bug of GMP or anything else? Any hints how to get a control over
this SegFault are appreciated. Even if there is memory shortage (though
there shouldn't be, right?), I would expect a more graceful exit.
Thanks,
Pearu
/* begin of test code */
#include <stdio.h>
#include "gmp.h"
#define BA 2
#define EX 111111111
static void * gmpy_allocate(size_t size);
static void * gmpy_reallocate(void *ptr, size_t old_size, size_t
new_size);
static void gmpy_free( void *ptr, size_t size);
main () {
mpz_t b;
mp_set_memory_functions( gmpy_allocate, gmpy_reallocate, gmpy_free );
printf("Calculating %d**%d:\n",BA,EX);
mpz_init_set_ui(b,BA);
mpz_pow_ui(b,b,EX);
printf("sizein10(%d**%d)=%d\n",BA,EX,mpz_sizeinbase(b,10));
}
static void * gmpy_allocate(size_t size)
{
void *res;
res = (void *)malloc(size);
fprintf(stderr, "mp_allocate( %d ) ->%8p\n", size, res);
return res;
}
static void *
gmpy_reallocate(void *ptr, size_t old_size, size_t new_size)
{
void *res;
fprintf(stderr,
"mp_reallocate: old address %8p, old size %d, new %d\n",
ptr, old_size, new_size);
res = (void *)realloc(ptr, new_size);
fprintf(stderr, "mp_reallocate: newob address %8p, newob size %d\n",
res, new_size);
return res;
}
static void
gmpy_free( void *ptr, size_t size)
{
fprintf(stderr, "mp_free : old address %8p, old size %d\n",
ptr, size);
free(ptr);
}
/* EOF */
- SegFault in 2**111111111 calculation,
Pearu Peterson <=
Re: SegFault in 2**111111111 calculation, Kevin Ryde, 2000/12/06