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
Wayne Davison <wayne@opencoder.net>
Date
Mar 5, 2008, 15:54 UTC
Message-ID
<20080305155412.GA19295@herod.dreamhost.com>
In-Reply-To
<200803051600.06605.michal.rokos@nextsoft.cz>
On Wed, Mar 05, 2008 at 04:00:06PM +0100, Michal Rokos wrote:
> +		[[char buf[1];
> +		  if (test_vsnprintf(buf, 1, "%s", "12345") != 5) return 1;
> +		  if (snprintf(buf, 1, "%s", "12345") != 5) return 1]])],

I'd suggest using a longer buf, requesting a longer length (e.g. 3 instead of 1), and then making sure that the resulting buf is right (e.g. "12" instead of "123").

		[[char buf[6];
		  if (test_vsnprintf(buf, 3, "%s", "12345") != 5
		   || strcmp(buf, "12") != 0) return 1;
		  if (snprintf(buf, 3, "%s", "12345") != 5
		   || strcmp(buf, "12") != 0) return 1]])],

Then, set a define that snprintf is bogus and use a version of snprintf() based on this instead:

http://rsync.samba.org/ftp/unpacked/rsync/lib/snprintf.c

That defines rsync_snprintf() and rsync_vsnprintf() functions (which could be renamed for git). Then, in a global .h file, add something like this:

#if !defined HAVE_VSNPRINTF || !defined HAVE_C99_VSNPRINTF #define vsnprintf rsync_vsnprintf int vsnprintf(char *str, size_t count, const char *fmt, va_list args); #endif

#if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF #define snprintf rsync_snprintf int snprintf(char *str, size_t count, const char *fmt,...); #endif

Just be sure to put those that after the various system includes so that they are not adversely affected.

..wayne..
Previous: Michal RokosNext: Johannes Sixt
Message 16 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.