realloc problems

Philip Lee rocketman768 at gmail.com
Tue Mar 21 04:18:52 CET 2006


Hey. I'm writing a program that deals with matrices, and I am having a
really strange problem with GMP. There is a certain function that I call
mtx_bool_read() that is supposed to read in a matrix from a filestream. The
problem is that it works, but not in each of the modules I write. The times
it doesn't work, it dumps one of these into the terminal window:

*** glibc detected *** realloc(): invalid size: 0xb7f98938 ***
or
Program received signal SIGSEGV, Segmentation fault.
0xb7e139ca in realloc () from /lib/tls/i686/cmov/libc.so.6

I call mpz_inp_raw(), then that leads to...well, I'll just give you the gdb:

458             for( i=0; i < a->rows; i++ )
(gdb) n
459                     mpz_inp_raw( a->rowlabels[i], fp );
(gdb) n
458             for( i=0; i < a->rows; i++ )
(gdb) n
459                     mpz_inp_raw( a->rowlabels[i], fp );
(gdb) n
458             for( i=0; i < a->rows; i++ )
(gdb) n
459                     mpz_inp_raw( a->rowlabels[i], fp );
(gdb) s
__gmpz_inp_raw (x=0x0, fp=0x81cd2a0) at inp_raw.c:88
88      {
(gdb) n
97          fp = stdin;
(gdb) n
100       if (fread (csize_bytes, sizeof (csize_bytes), 1, fp) != 1)
(gdb) n
115       abs_csize = ABS (csize);
(gdb) n
118       abs_xsize = (abs_csize*8 + GMP_NUMB_BITS-1) / GMP_NUMB_BITS;
(gdb) n
120       if (abs_xsize != 0)
(gdb) n
122           MPZ_REALLOC (x, abs_xsize);
(gdb) s
122           MPZ_REALLOC (x, abs_xsize);
(gdb) s
__gmpz_realloc (m=0x818e888, new_alloc=4) at realloc.c:27
27      {
(gdb) n
31        new_alloc = MAX (new_alloc, 1);
(gdb) n
33        mp = __GMP_REALLOCATE_FUNC_LIMBS (PTR(m), ALLOC(m), new_alloc);
(gdb) n
*** glibc detected *** realloc(): invalid size: 0xb7f98938 ***

Program received signal SIGABRT, Aborted.
0xffffe410 in __kernel_vsyscall ()

So, we get some sort of abort. Does anybody know the common mistakes that
might cause such a problem? I am a little hesitant to post the code since it
is in the thousands of lines, but if someone wants to take a look at it, by
all means just ask. Oh, why is mpz_inp_raw() even calling mpz_realloc() ?? I
thought the integers never shrunk on their own.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20060321/d2aa2f77/attachment.html


More information about the gmp-discuss mailing list