From: Michal Rokos <michal.rokos@nextsoft.cz>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: 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 09:37:39 +0100 [thread overview]
Message-ID: <200803050937.40345.michal.rokos@nextsoft.cz> (raw)
In-Reply-To: <47CD78C9.80003@viscovery.net>
Hello,
On Tuesday 04 March 2008 17:28:57 Johannes Sixt wrote:
> Michal Rokos schrieb:
> > If anybody could think of some better define than BROKEN_VSNPRINTF, I'm
> > all ears.
>
> CLUELESS_OVERFLOWN_VSNPRINTF?
Heh. My first one was VSNPRINTF_RETURNS_MINUS_1...
> Because we have the same issue on Windows where vsnprintf returns -1 on
> overflow.
>
> But there is also another complication: The size parameter of the system's
> vsnprintf must not count the trailing NUL, i.e. the buffer must actually
> have space for one extra byte, whereas the POSIX version must count NUL.
> Can you check whether your vsnprintf has this flaw, too? If it doesn't, we
> would need another configuration variable so that we can distinguish these
> two kinds of brokenness.
I did my homework and prepared this:
#include "stdio.h"
#include "stdarg.h"
int test_vsnprintf(char *str, size_t maxsize, const char *format, ...)
{
int ret;
va_list ap;
va_start(ap, format);
ret = vsnprintf(str, maxsize, format, ap);
va_end(ap);
return ret;
}
int main(void)
{
char buf[10];
int ret;
ret = test_vsnprintf(buf, 1, "%s", "12345");
printf("case1: %d\n", ret);
ret = test_vsnprintf(buf, 5, "%s", "12345");
printf("case2: %d\n", ret);
ret = test_vsnprintf(buf, 6, "%s", "12345");
printf("case3: %d\n", ret);
ret = test_vsnprintf(buf, 10, "%s", "12345");
printf("case4: %d\n", ret);
return 0;
}
which returns:
Linux 2.6.25-rc3-mr i686
case1: 5
case2: 5
case3: 5
case4: 5
HP-UX B.11.11 9000/800
case1: -1
case2: -1
case3: 5
case4: 5
HP-UX B.11.23 ia64
case1: -1
case2: -1
case3: 5
case4: 5
So HPUX impl is the same as a Windows one. So we can share the replacement.
Please note that there's no va_copy() on HPUX.
I think that Tru64 has the same issue, but I have no HW to test it on now.
Could somebody else try to run testcase above on some other OSes?
Thanks
Michal
next prev parent reply other threads:[~2008-03-05 8:38 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 [this message]
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
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=200803050937.40345.michal.rokos@nextsoft.cz \
--to=michal.rokos@nextsoft.cz \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
/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).