gmp_printf bug?

Zimmermann Paul Paul.Zimmermann at loria.fr
Wed Jul 20 10:33:25 CEST 2011


       Torbjörn,

> I am unable to reproduce this problem.
> 
> I attempted to reproduce it on both the main GMP development machine
> (athlon64-pc-freebsd8.1) and on a GNU/Linux machine (x86_64-linux-gnu).
> 
> There is surely a bug somewhere, in GMP or in the environment you're
> using (e.g., glibc).  It would be good if someone could isolate the
> problem.

on gcc20.fsffrance.org, which you have access to, I can reproduce the problem
with the program below:

zimmerma at gcc20:~$ gcc -Iinclude g.c lib/libgmp.a;./a.out
libc version: 2.11.2
GMP 5.0.1 library 5.0.1
0.111349511949672485115e405025890106316193
*** glibc detected *** ./a.out: realloc(): invalid pointer: 0x0000000000623008 ***

Note that on other computers from the GCC Compile Farm, I get other strange
results:

zimmerma at gcc16:~/gmp-5.0.1$ ./a.out 
libc version: 2.7
GMP 5.0.1 library 5.0.1
0.111349511949672485115e405025890106316193
4.850018e+405025890106316192

zimmerma at gcc16:~/gmp-5.0.2$ ./a.out 
libc version: 2.7
GMP 5.0.2 library 5.0.2
0.111349511949672485115e405025890106316193
0.000000e+405025890106316193

zimmerma at gcc11:~$ ./a.out 
libc version: 2.7
GMP 5.0.1 library 5.0.1
0.111349511949672485115e405025890106316193
i.r00000e+405025890106316192

Maybe this is a glibc bug, anyway you can now isolate the problem, and report
it to the glibc developers if needed.

Paul

#include <stdio.h>
#include <stdlib.h>
#include <gnu/libc-version.h>
#include "gmp.h"

main(int argc, char *argv[])
  {
    mpf_t f;

    printf("libc version: %s\n", gnu_get_libc_version());
    printf ("GMP %d.%d.%d library %s\n",
            __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL,
            gmp_version);
    mpf_init2 (f, 2);
    mpf_set_ui (f, 1);
    mpf_mul_2exp (f, f, 1345466883500933130);
    mpf_dump (f);
    gmp_printf("%Fe\n", f);
    mpf_clear (f);
  }



More information about the gmp-bugs mailing list