From: Johannes Sixt <j.sixt@viscovery.net>
To: Brandon Casey <casey@nrlssc.navy.mil>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] compat/snprintf.c: handle snprintf's that always return the # chars transmitted
Date: Thu, 21 Aug 2008 10:06:31 +0200 [thread overview]
Message-ID: <48AD2207.903@viscovery.net> (raw)
In-Reply-To: <nYV6zI97uDEOlIEFjH5oAZW1lTFm0mOVlTrIxzRyOY5CCrUJw7ROgA@cipher.nrlssc.navy.mil>
Brandon Casey schrieb:
> Some platforms provide a horribly broken snprintf. More broken than the
> platforms that return -1 when there is too little space in the target buffer
> for the formatted string. Some platforms provide an snprintf which _always_
> returns the number of characters transmitted to the buffer, regardless of
> whether there was enough space or not.
...
> diff --git a/compat/snprintf.c b/compat/snprintf.c
> index 580966e..357e733 100644
> --- a/compat/snprintf.c
> +++ b/compat/snprintf.c
> @@ -17,6 +17,8 @@ int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
>
> if (maxsize > 0) {
> ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
> + if (ret == maxsize-1)
> + ret = -1;
> /* Windows does not NUL-terminate if result fills buffer */
> str[maxsize-1] = 0;
> }
> @@ -34,6 +36,8 @@ int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
> break;
> s = str;
> ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
> + if (ret == maxsize-1)
> + ret = -1;
> }
> free(s);
> return ret;
This looks good, and it passes the test suite on MinGW. Hence:
Acked-by: Johannes Sixt <johannes.sixt@telecom.at>
-- Hannes
prev parent reply other threads:[~2008-08-21 8:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-21 1:53 [PATCH] compat/snprintf.c: handle snprintf's that always return the # chars transmitted Brandon Casey
2008-08-21 8:06 ` Johannes Sixt [this message]
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=48AD2207.903@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=casey@nrlssc.navy.mil \
--cc=git@vger.kernel.org \
/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).