From: Johannes Sixt Date: Wed, 05 Mar 2008 15:22:11 GMT Subject: Re: [PATCH] Add compat/vsnprintf.c for systems that returns -1 on maxsize reached 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. > +#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; > + 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? > + s = str; > + ret = vsnprintf(str, maxsize, format, ap); > + } > + free(s); > + return ret; > +} -- Hannes