[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] Re: snprintf
From: |
Simon Josefsson |
Subject: |
[Bug-gnulib] Re: snprintf |
Date: |
Fri, 01 Oct 2004 15:05:21 +0200 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
Bruno Haible <address@hidden> writes:
>> And with the patch below it might even compile...
>
> I've committed a similar patch. Still there are two issues:
>
> - What if size == 0 ?
Ah, right. This should fix it:
2004-10-01 Simon Josefsson <address@hidden>
* snprintf.c (snprintf): Handle size==0.
Index: snprintf.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/snprintf.c,v
retrieving revision 1.3
diff -u -p -u -w -r1.3 snprintf.c
--- snprintf.c 1 Oct 2004 10:26:52 -0000 1.3
+++ snprintf.c 1 Oct 2004 13:04:45 -0000
@@ -55,7 +55,7 @@ snprintf (char *str, size_t size, const
if (!output)
return -1;
- if (str)
+ if (str && size > 0)
{
memcpy (str, output, MIN (len + 1, size));
str[size - 1] = '\0';
> - Why do you let vasnprintf allocate the entire string if, afterwards,
> you only need size bytes of it? You could already tell vasnprintf
> to produce less memory.
How?
Thanks.