git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wayne Davison <wayne@opencoder.net>
To: Michal Rokos <michal.rokos@nextsoft.cz>
Cc: Johannes Sixt <j.sixt@viscovery.net>, GIT <git@vger.kernel.org>
Subject: Re: [PATCH] Add compat/vsnprintf.c for systems that returns -1 on maxsize reached
Date: Wed, 5 Mar 2008 07:54:12 -0800	[thread overview]
Message-ID: <20080305155412.GA19295@herod.dreamhost.com> (raw)
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..

  parent reply	other threads:[~2008-03-05 15:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-04 13:59 [PATCH] Add compat/vsnprintf.c for systems that returns -1 on maxsize reached Michal Rokos
2008-03-04 14:09 ` Johannes Schindelin
2008-03-04 14:09 ` Finn Arne Gangstad
2008-03-04 16:19   ` Johannes Sixt
2008-03-04 14:12 ` Morten Welinder
2008-03-04 16:28 ` Johannes Sixt
2008-03-04 23:51   ` Wayne Davison
2008-03-05  8:37   ` Michal Rokos
2008-03-05  8:44     ` Jeff King
2008-03-05  9:18     ` Johannes Sixt
2008-03-05 13:55       ` Michal Rokos
2008-03-05 14:28         ` Johannes Sixt
2008-03-05 15:00           ` Michal Rokos
2008-03-05 15:22             ` Johannes Sixt
2008-03-05 15:48               ` Michal Rokos
2008-03-05 15:54             ` Wayne Davison [this message]
2008-03-05 16:04               ` Johannes Sixt
2008-03-05 22:33                 ` Wayne Davison
2008-03-05 21:05               ` Junio C Hamano
2008-03-05  9:22     ` Mike Ralphson
2008-03-05 10:35     ` Robert Haines
2008-03-05 13:58       ` Michal Rokos
2008-03-10  8:59   ` Michal Rokos
2008-03-10  9:28     ` Johannes Sixt
2008-03-10  9:47       ` Michal Rokos
2008-03-10 10:05         ` Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080305155412.GA19295@herod.dreamhost.com \
    --to=wayne@opencoder.net \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    --cc=michal.rokos@nextsoft.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).