Re: [PATCH] Add compat/vsnprintf.c for systems that returns -1 on maxsize reached
- From
Finn Arne Gangstad <finnag@pvv.org>
- Date
- Mar 4, 2008, 14:09 UTC
- Message-ID
- <20080304140930.GA23335@pvv.org>
- In-Reply-To
- <200803041459.29000.michal.rokos@nextsoft.cz>
On Tue, Mar 04, 2008 at 02:59:28PM +0100, Michal Rokos wrote:
Show 7 quoted lines
> + while ( ret == -1 )
> + {
> + maxsize = (maxsize*3)/2;
> + s = realloc(s, maxsize);
> + if (! s) return -1;
> + ret = vsnprintf(s, maxsize, format, ap); /* <--- UNSAFE! */
> + }This is not generally safe, you cannot call vsnprintf multiple times with the same ap on all architectures. You need va_copy (or __va_copy, or VA_COPY, differs a bit between different architectures, especially one the ones with a broken vsnprintf I guess..)
- Finn Arne