Bug#700573: wheezy-amd64: reusing the same va_list with vsnprintf() gives a print error
Package: libc6
Version: 2.11.3-4
Severity: normal
/*
This bugg is not on wheezy-i386, squeeze-i386, squeeze-arm
Maybe I should not use vsnprintf() twice with the same va_list but it works
elsewhere
Here is how I use vsnprintf() :
The error return value of vsnprintf() is the number of characters which
would have been written to the final string
if enough space had been available.
On squeeze and earlier, I create this normal error to get the length of the
needed buffer.
To create this error I first call vsnprintf() with size=0 (I tried with
greater sizes but the bugg remained)
Then I allocate the needed buffer (like vasprintf does internally) and call
vsnprintf() again with right size.
Howerver, on wheezy-amd64, this does not work if I use the same va_list for
the two vsnprintf() calls.
I have to use a second va_list to get it work
The system information given here is the one of my squeeze internet PC
the wheezy PC is not connected to internet
Here are some informations about libc6 in my wheezy-amd64
wheezy-amd64> ls -l /lib/x86_64-linux-gnu/libc.so.6
lrwxrwxrwx 1 root root 12 Feb 14 12:21 /lib/x86_64-linux-
gnu/libc.so.6 -> libc-2.13.so
*/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
void trace (const char *chFormat, ...) {
va_list args1, args2;
va_start(args1, chFormat);
va_start(args2, chFormat);
char buff[100]; // no dynamic allocation for this example
int iBufSize = vsnprintf(buff, 0, chFormat, args1); // calculates the
minimum size of the buffer
vsnprintf(buff, 90, chFormat, args1); // wrong result when
using the previous va_list: args1 instead of args2
printf("vsnprintf : buff size= %d\n", iBufSize); // reports the right
size
printf("vsnprintf : %s", buff);
va_end(args1);
va_end(args2);
}
int main(int argc, char **argv)
{
int i=8;
trace("int=%d\n", i);
}
/*
Wrong in wheezy-amd64 when using the same va_list args2 = args1
./a.out prints:
vsnprintf : buff size= 6
vsnprintf : int=1065712984
OK in wheezy-amd64when using two different va_list args2 != args1
OK in squeeze and wheezy-i386 when using the same va_list args2 = args1
./a.out prints:
vsnprintf : buff size= 6
vsnprintf : int=8
*/
-- System Information:
Debian Release: 6.0.6
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: i386 (i686)
Kernel: Linux 3.2.35.01 (SMP w/1 CPU core)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages libc6 depends on:
ii libc-bin 2.11.3-4 Embedded GNU C Library: Binaries
ii libgcc1 1:4.4.5-8 GCC support library
Versions of packages libc6 recommends:
ii libc6-i686 2.11.3-4 Embedded GNU C Library: Shared lib
Versions of packages libc6 suggests:
ii debconf [debconf-2.0] 1.5.36.1 Debian configuration management sy
pn glibc-doc <none> (no description available)
ii locales 2.11.3-4 Embedded GNU C Library: National L
-- debconf information:
glibc/upgrade: true
glibc/restart-services:
glibc/disable-screensaver:
glibc/restart-failed:
Reply to: