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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux