Re: [PATCH 1/5] strbuf API additions and enhancements.
- From
- Kalle Olavi Niemitalo <kon@iki.fi>
- Date
- Sep 20, 2007, 07:20 UTC
- Message-ID
- <87lkb1iz0i.fsf@Astalo.kon.iki.fi>
- In-Reply-To
- <46F21097.5030901@eudaptics.com>
Johannes Sixt <j.sixt@eudaptics.com> writes:
Show 7 quoted lines
> Edgar Toernig schrieb: >> The second vsnprintf won't work as the first one consumed all args >> from va_list ap. You need to va_copy the ap. > > Your analysis is not correct. The second vsnprintf receives the same > argument pointer as the first, and, hence, consumes the same set of > arguments.
C99 7.9.16.2p2 has a footnote: "As the functions vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, and vsscanf invoke the va_arg macro, the value of arg after the return is indeterminate."
Normative text in 7.15p3 confirms this: "The object ap may be passed as an argument to another function; if that function invokes the va_arg macro with parameter ap, the value of ap in the calling function is indeterminate and shall be passed to the va_end macro prior to any further reference to ap."
Therefore va_copy is needed here, at least in principle.