Re: [PATCH] Add compat/vsnprintf.c for systems that returns -1 on maxsize reached
- From
Johannes Sixt <j.sixt@viscovery.net>
- Date
- Mar 5, 2008, 15:22 UTC
- Message-ID
- <47CEBAA3.5060109@viscovery.net>
- In-Reply-To
- <200803051600.06605.michal.rokos@nextsoft.cz>
Michal Rokos schrieb:
> Thank you for your comments; is this better?
Better, but still not there. See below. The configure test looks fine, but I can't test it.
Finally, please make this a proper patch with Signed-off-by for Junio to pick up.
Show 11 quoted lines
> +#undef vsnprintf
> +int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
> +{
> + char *s;
> +
> + int ret = vsnprintf(str, maxsize, format, ap);
> + if (ret != -1 )
> + return ret;
> +
> + s = NULL;
> +What if maxsize == 0? Insert here:
if (maxsize < 250) maxsize = 250;
Show 7 quoted lines
> + while (ret == -1) {
> + maxsize *= 4;
> + str = realloc(s, maxsize);
> + if (! str) {
> + free(s);
> + return -1;
> + }ret == -1 at this time, so:
if (!str) break;
Hm?
Show 6 quoted lines
> + s = str; > + ret = vsnprintf(str, maxsize, format, ap); > + } > + free(s); > + return ret; > +}
-- Hannes