git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Michal RokosNext: Michal Rokos
Message 14 of 26 in “Add compat/vsnprintf.c for systems that returns -1 on maxsize reached”
  1. Add compat/vsnprintf.c for systems that returns -1 on maxsize reachedMichal Rokos, Mar 4, 2008
  2. Johannes SchindelinMar 4, 2008
  3. Finn Arne GangstadMar 4, 2008
  4. Johannes SixtMar 4, 2008
  5. Morten WelinderMar 4, 2008
  6. Johannes SixtMar 4, 2008
  7. Wayne DavisonMar 4, 2008
  8. Michal RokosMar 5, 2008
  9. Jeff KingMar 5, 2008
  10. Johannes SixtMar 5, 2008
  11. Michal RokosMar 5, 2008
  12. Johannes SixtMar 5, 2008
  13. Michal RokosMar 5, 2008
  14. Johannes SixtMar 5, 2008
  15. Michal RokosMar 5, 2008
  16. Wayne DavisonMar 5, 2008
  17. Johannes SixtMar 5, 2008
  18. Wayne DavisonMar 5, 2008
  19. Junio C HamanoMar 5, 2008
  20. Mike RalphsonMar 5, 2008
  21. Robert HainesMar 5, 2008
  22. Michal RokosMar 5, 2008
  23. Michal RokosMar 10, 2008
  24. Johannes SixtMar 10, 2008
  25. Michal RokosMar 10, 2008
  26. Johannes SixtMar 10, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.