[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] vasnprintf cleanup

From: Derek Robert Price
Subject: [Bug-gnulib] vasnprintf cleanup
Date: Thu, 14 Oct 2004 23:43:57 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040616

Hey all,

Attached is a very short patch which updates vasnprintf to not access
lengthp when resultbuf == NULL and lengthp == NULL to avoid annoying
artificial constructs like the following:

    ...coding happily away...
       size_t dummy;
       somevar = asnprintf (NULL, &dummy, "%s/%s", foo, bar);

2004-10-14  Derek R. Price  <address@hidden>

    * lib/vasnprintf.c (vasnprintf): Validate lengthp before
dereferencing it.
    * vasnprintf.h: Update comment to match.




Email: address@hidden

Get CVS support at <http://ximbiot.com>!

Index: lib/vasnprintf.c
RCS file: /cvsroot/gnulib/gnulib/lib/vasnprintf.c,v
retrieving revision 1.14
diff -u -p -r1.14 vasnprintf.c
--- lib/vasnprintf.c    8 Sep 2004 12:11:19 -0000       1.14
+++ lib/vasnprintf.c    15 Oct 2004 03:32:13 -0000
@@ -861,7 +861,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l
     if (buf_malloced != NULL)
       free (buf_malloced);
     CLEANUP ();
-    *lengthp = length;
+    if (lengthp) *lengthp = length;
     if (length > INT_MAX)
       goto length_overflow;
     return result;
Index: lib/vasnprintf.h
RCS file: /cvsroot/gnulib/gnulib/lib/vasnprintf.h,v
retrieving revision 1.3
diff -u -p -r1.3 vasnprintf.h
--- lib/vasnprintf.h    1 Oct 2004 20:42:15 -0000       1.3
+++ lib/vasnprintf.h    15 Oct 2004 03:37:53 -0000
@@ -46,8 +46,8 @@ extern "C" {
    size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
    If successful, return the address of the string (this may be = RESULTBUF
    if no dynamic memory allocation was necessary) and set *LENGTHP to the
-   number of resulting bytes, excluding the trailing NUL.  Upon error, set
-   errno and return NULL.
+   number of resulting bytes, excluding the trailing NUL, if LENGTHP is not
+   NULL.  Upon error, set errno and return NULL.
    When dynamic memory allocation occurs, the preallocated buffer is left
    alone (with possibly modified contents).  This makes it possible to use

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]