Subject: Re: [PATCH] Add compat/vsnprintf.c for systems that returns -1 on maxsize reached

From: Johannes Sixt <[email-masked]>
Date: Wed, 05 Mar 2008 16:22:11 +0100

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