<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1561" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN 
class=294583614-04122006>Hi,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=294583614-04122006></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=294583614-04122006>I am executing a 
piece of code which continually tries to do the sprintf into the allocated 
buffer on a 64-bit RedHat linux machine. </SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=294583614-04122006></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=294583614-04122006>Here are the details 
of the system and the gcc version used - </SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>bash-3.00$ uname -a<BR>Linux <SPAN 
class=294583614-04122006>saumya.foo.com </SPAN>2.6.9-5.ELsmp #1 SMP Wed Jan 5 
19:29:47 EST 2005 x86_64 x86_64 x86_64 GNU/Linux<BR></FONT><FONT face=Arial 
size=2></DIV></FONT>
<DIV><FONT face=Arial size=2>bash-3.00$ gcc -v<BR>Reading specs from 
/usr/lib/gcc/x86_64-redhat-linux/3.4.3/specs<BR>Configured with: ../configure 
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared 
--enable-threads=posix --disable-checking --with-system-zlib 
--enable-__cxa_atexit --disable-libunwind-exceptions 
--enable-languages=c,c++,objc,java,f77 --enable-java-awt=gtk 
--host=x86_64-redhat-linux<BR>Thread model: posix<BR>gcc version 3.4.3 20041212 
(Red Hat 3.4.3-9.EL4)</FONT><FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=294583614-04122006><FONT face=Arial size=2>On executing the 
code (snippet below) I get a segmentation fault at run time. The code builds 
fine. The same code runs fine on a 32-bit linux machine.</FONT></SPAN></DIV>
<DIV><SPAN class=294583614-04122006><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=294583614-04122006><FONT face=Arial size=2> if (NULL != 
*strp) {<BR>        for ( ; NULL != *strp; ) 
{<BR>            left = 
*sizep - len - 
1;<BR>            if 
(left > 0) 
{<BR>                
result = vsnprintf(&(*strp)[len], left, format, 
ap);<BR>                
if ((result != -1) && (result < left)) {  //vsnprintf 
truncated the output 
string<BR>                    
break;<BR>                
}<BR>            
}<BR>            *sizep 
*= 2;<BR>            
Renew(*strp, *sizep, char); //reallocate sizep amount of space to 
strp<BR>        }<BR>    
}<BR></FONT></SPAN></DIV>
<DIV><SPAN class=294583614-04122006><FONT face=Arial size=2>The crash happens in 
the second iteration of the for loop. It goes through fine in the first 
iteration.</FONT></SPAN></DIV>
<DIV><SPAN class=294583614-04122006><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=294583614-04122006><FONT face=Arial size=2>Here is the gdb 
backtrace -</FONT></SPAN></DIV></FONT>
<DIV><FONT><SPAN class=294583614-04122006><FONT face=Arial 
size=2></FONT></SPAN> </DIV></FONT>
<DIV><FONT face=Arial size=2>#0  0x00000037d776fc10 in strlen () from 
/lib64/tls/libc.so.6<BR>#1  0x00000037d7742b4b in vfprintf () from 
/lib64/tls/libc.so.6<BR>#2  0x00000037d7761ce4 in vsnprintf () from 
/lib64/tls/libc.so.6<BR>#3  0x00000000004965a6 in str_vappend 
(strp=0x7fbfffe790, sizep=0x7fbfffe788, <BR>    format=0x4adf1b 
"%s /%s HTTP/1.1\r\n", ap=0x7fbfffe7e0) at str.c:684</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT><SPAN class=294583614-04122006><FONT face=Arial size=2>Is this a 
known issue with vsnprintf() on 64-bit linux platforms? Is there a fix or any 
workaround available?</FONT></SPAN></FONT></DIV>
<DIV><FONT><SPAN class=294583614-04122006><FONT face=Arial 
size=2></FONT></SPAN></FONT> </DIV>
<DIV><FONT><SPAN class=294583614-04122006><FONT face=Arial 
size=2>Thanks,</FONT></SPAN></FONT></DIV>
<DIV><FONT><SPAN class=294583614-04122006><FONT face=Arial 
size=2>saumya</FONT></SPAN></DIV></FONT></BODY></HTML>