S
saumya.agarwal
Hi,
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.
Here are the details of the system and the gcc version used -
bash-3.00$ uname -a
Linux saumya.foo.com 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:29:47 EST 2005
x86_64 x86_64 x86_64 GNU/Linux
bash-3.00$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.3/specs
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
Thread model: posix
gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
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.
if (NULL != *strp) {
for ( ; NULL != *strp; ) {
left = *sizep - len - 1;
if (left > 0) {
result = vsnprintf(&(*strp)[len], left, format, ap);
if ((result != -1) && (result < left)) { //vsnprintf
truncated the output string
break;
}
}
*sizep *= 2;
Renew(*strp, *sizep, char); //reallocate sizep amount of
space to strp
}
}
The crash happens in the second iteration of the for loop. It goes
through fine in the first iteration.
Here is the gdb backtrace -
#0 0x00000037d776fc10 in strlen () from /lib64/tls/libc.so.6
#1 0x00000037d7742b4b in vfprintf () from /lib64/tls/libc.so.6
#2 0x00000037d7761ce4 in vsnprintf () from /lib64/tls/libc.so.6
#3 0x00000000004965a6 in str_vappend (strp=0x7fbfffe790,
sizep=0x7fbfffe788,
format=0x4adf1b "%s /%s HTTP/1.1\r\n", ap=0x7fbfffe7e0) at
str.c:684
Is this a known issue with vsnprintf() on 64-bit linux platforms? Is
there a fix or any workaround available?
Thanks,
saumya
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.
Here are the details of the system and the gcc version used -
bash-3.00$ uname -a
Linux saumya.foo.com 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:29:47 EST 2005
x86_64 x86_64 x86_64 GNU/Linux
bash-3.00$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.3/specs
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
Thread model: posix
gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
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.
if (NULL != *strp) {
for ( ; NULL != *strp; ) {
left = *sizep - len - 1;
if (left > 0) {
result = vsnprintf(&(*strp)[len], left, format, ap);
if ((result != -1) && (result < left)) { //vsnprintf
truncated the output string
break;
}
}
*sizep *= 2;
Renew(*strp, *sizep, char); //reallocate sizep amount of
space to strp
}
}
The crash happens in the second iteration of the for loop. It goes
through fine in the first iteration.
Here is the gdb backtrace -
#0 0x00000037d776fc10 in strlen () from /lib64/tls/libc.so.6
#1 0x00000037d7742b4b in vfprintf () from /lib64/tls/libc.so.6
#2 0x00000037d7761ce4 in vsnprintf () from /lib64/tls/libc.so.6
#3 0x00000000004965a6 in str_vappend (strp=0x7fbfffe790,
sizep=0x7fbfffe788,
format=0x4adf1b "%s /%s HTTP/1.1\r\n", ap=0x7fbfffe7e0) at
str.c:684
Is this a known issue with vsnprintf() on 64-bit linux platforms? Is
there a fix or any workaround available?
Thanks,
saumya