On 10.05.15 10.44, Öö Tiib wrote:
>> Furthermore using a static buffer fixes the problem for him. This
>> wouldn't fix and parameter type issues.
>
> Is the issue caused by calling vsnprintf twice or caused by usage
> of '&str[0]' for buffer?
It is not fully proven, but it seems that the first one is the problem.
>> There is a pragma for gcc to enforce that whereever ... is used this
>> way. (And I never used ... for anything else.)
>
> I didn't know of such pragma existing. What pragma it is?
#ifdef __GNUC__
#define PRINTFATTR(i) __attribute__((format(printf, i, i+1)))
#else
#define PRINTFATTR(i)
#endif
string vstringf(const char* format, va_list va);
string stringf(const char* format, ...) PRINTFATTR(1);
> The library that uses variadic templates is usually couple of header
> files ... but indeed, anything can cause problems.
Especially cross platform. Another guy already complained about C++11
because Debian Wheezy (gcc 4.7) does not support it. (Interestingly gcc
4.7 of OS/2 supports it - however.)
>> He tries to dig it. It seems that invoking vsnprintf twice with the same
>> va raises the problem.
>
> So something of the 'int count = vsnprintf(NULL, 0, format, va);' corrupts
> 'va' for next call?
It seems so. No Idea what is going on. I can't test it since it works on
all of my platforms including Raspberry Pi (ARM hf) and the prehistoric
OS/2. OK, all of them use a gcc flavor.
> If he uses fixed buffer in next call (that ignores
> the 'count') then does he get garbage in fixed buffer as well?
We did not test that so far. The fixed buffer does not use NULL but
passes sizeof(buffer) on the first call instead.
Marcel