bug-gmp
[Top][All Lists]
Advanced

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

Bug report for gmp_printf with a string %s


From: Eric D. Russell
Subject: Bug report for gmp_printf with a string %s
Date: Fri, 13 Dec 2002 16:19:52 -0700

Greetings -

I've pretty much convinced myself I'm seeing a bug in gmp_printf and it's
not my code - unless I'm doing somwthing I'm not supposed to do.


Of course it could be the compiler...


The problem is that if there is a string variable near mpz_t variables in
printf's it seg faults depending on where the %s is.
This is just an annoying error, since I know about it I just don't do it.

The test program below should rerpduce the error unless it's my system.



### GMP version: (unpatched)  
grep VERSION *.h
config.h:#define VERSION "4.1"
gmp.h:#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \
gmp.h:#define __GNU_MP_VERSION 4
gmp.h:#define __GNU_MP_VERSION_MINOR 1
gmp.h:#define __GNU_MP_VERSION_PATCHLEVEL 0


### OS: Red Hat Linux 7.3
uname -a
Linux sadl10755 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686 unknown


### congif.guess:
pentium3-pc-linux-gnu


### configfsf.guess:
i686-pc-linux-gnu


### C Version:
cc -v
Reading specs from /usr/lib/gint
cc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)


###  ./configure  was it, then make


####################### Test Program 
################################################################################


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

   // this is the data to sscanf and printf.

   char* line = "1 2 3 ross 4 5 145507181280 145507181281 145507181282 
145507181283 145507181284 145507181285
145507181286 145507181287 9 8 7 6 145507181289";

   int m, su, sss, xbar, port;
   int a, b, c, d;

   char host[256];

   mpz_t uptime, good, bad, timeouts, illegal_symbols, missed_beats, 
bad_routes, dead_routes, transmit_timeouts;

   mpz_init( uptime );
   mpz_init( timeouts);
   mpz_init( good );
   mpz_init( bad );
   mpz_init( illegal_symbols );
   mpz_init( missed_beats );
   mpz_init( bad_routes );
   mpz_init( dead_routes );
   mpz_init( transmit_timeouts );

   // first parse the data in line.

   gmp_sscanf( line, "%d %d %d %s %d %d %Zd %Zd %Zd %Zd %Zd %Zd %Zd %Zd %d %d 
%d %d %Zd", 
               &m, &su, &sss, host, &xbar, &port,
               uptime, good, bad, timeouts, illegal_symbols, missed_beats, 
bad_routes, dead_routes,
               &a, &b, &c, &d, 
               transmit_timeouts );

  // A variety of printfs to see if everything got read in correctly, and it 
looks ok.

  gmp_printf("uptime=%Zd\n", uptime );
  gmp_printf("good=%Zd\n", good );
  gmp_printf("timeouts=%Zd\n\n", timeouts );

  gmp_printf("m=%d su=%d sss=%d host=%s xbar=%d port=%d host=%s\n\n",
              m, su, sss, host, xbar, port, host );

  gmp_printf("uptime=%Zd good=%Zd bad=%Zd timeouts=%Zd illegal_symbols=%Zd 
missed_beats=%Zd bad_routes=%Zd
dead_routes=%Zd transmit_timeouts=%Zd\n\n",
              uptime, good, bad, timeouts, illegal_symbols, missed_beats, 
bad_routes, dead_routes, transmit_timeouts );
  
  gmp_printf("a=%d b=%d c=%d d=%d\n\n", a, b, c, d );

  gmp_printf(" m=%d uptime=%Zd  a=%d\n\n",
            m, uptime, a );

  gmp_printf("host=%s. Length=%d\n\n", host, strlen(host) );

  // !!!!!!! Now we come to the problem.

  // The only difference between the following commands is where "host" is.
  // The first works, the 2nd gets a Segmentation Fault.
  // !!!

  gmp_printf(" host=%s m=%d su=%d sss=%d xbar=%d port=%d uptime=%Zd good=%Zd 
bad=%Zd timeouts=%Zd illegal_symbols=%Zd
missed_beats=%Zd bad_routes=%Zd dead_routes=%Zd transmit_timeouts=%Zd  a=%d 
b=%d c=%d d=%d  \n\n",
            host, m, su, sss, xbar, port, uptime, good, bad, timeouts, 
illegal_symbols, missed_beats, bad_routes,
dead_routes, transmit_timeouts, a, b, c, d );

  gmp_printf(" m=%d su=%d sss=%d xbar=%d port=%d host=%s uptime=%Zd good=%Zd 
bad=%Zd timeouts=%Zd illegal_symbols=%Zd
missed_beats=%Zd bad_routes=%Zd dead_routes=%Zd transmit_timeouts=%Zd  a=%d 
b=%d c=%d d=%d  \n\n",
            m, su, sss, xbar, port, host, uptime, good, bad, timeouts, 
illegal_symbols, missed_beats, bad_routes,
dead_routes, transmit_timeouts, a, b, c, d );



}



####################### Execution and back trace: 
###################################################################

uptime=145507181280
good=145507181281
timeouts=145507181283

m=1 su=2 sss=3 host=ross xbar=4 port=5 host=ross

uptime=145507181280 good=145507181281 bad=145507181282 timeouts=145507181283 
illegal_symbols=145507181284
missed_beats=145507181285 bad_routes=145507181286 dead_routes=145507181287 
transmit_timeouts=145507181289

a=9 b=8 c=7 d=6

 m=1 uptime=145507181280  a=9

host=ross. Length=4

 host=ross m=1 su=2 sss=3 xbar=4 port=5 uptime=145507181280 good=145507181281 
bad=145507181282 timeouts=145507181283
illegal_symbols=145507181284 missed_beats=145507181285 bad_routes=145507181286 
dead_routes=145507181287
transmit_timeouts=145507181289  a=9 b=8 c=7 d=6  


Program received signal SIGSEGV, Segmentation fault.
0x40055c7b in __gmpz_get_str () from /usr/lib/libgmp.so.3
(gdb) backtrace
#0  0x40055c7b in __gmpz_get_str () from /usr/lib/libgmp.so.3
#1  0x400689a6 in __gmp_doprnt () from /usr/lib/libgmp.so.3
#2  0x40069ae3 in __gmp_printf () from /usr/lib/libgmp.so.3
#3  0x08048f7d in main (argc=1, argv=0xbffff754) at test.c:74
#4  0x42017499 in __libc_start_main () from /lib/i686/libc.so.6




###################################################################################################################################################

-- 
========================================================================== 
Eric D. Russell                                        Phone: 505-844-3679 
Scalable Computing Systems Department (9223)           FAX:   505-845-7442 
Sandia National Labs, Mail Stop 1110             Email: address@hidden 
Albuquerque, NM  87185-1110                http://www.cs.sandia.gov/cplant 
==========================================================================

-- 
========================================================================== 
Eric D. Russell                                        Phone: 505-844-3679 
Scalable Computing Systems Department (9223)           FAX:   505-845-7442 
Sandia National Labs, Mail Stop 1110             Email: address@hidden 
Albuquerque, NM  87185-1110                http://www.cs.sandia.gov/cplant 
==========================================================================




reply via email to

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