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

[patches] Fix *asprintf() to be compatible with *BSD and sanity



 Sorry for not knowing about EGLIBC until you hit LWN, but anyway...

 Here is a, hopefully self explanatory, patch to fix *asprintf() to be
compatible with *BSD and what any sane C programmers expects. Drepper
NAKd it years ago...


commit fe9a68bb08316e5af9ee2e95ba7ecb0f1a6357a4
Author: James Antill <james@xxxxxxx>
Date:   Wed May 6 13:42:13 2009 -0400

     Fix *asprintf() to always have a valid pointer on return.
       Compatible with *BSD implementation.
       Compatible with C programmers expectation.

diff --git a/ChangeLog b/ChangeLog
index 0890030..e95f131 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-06  James Antill  <james@xxxxxxx>
+
+	* libio/vasprintf.c (_IO_vasprintf): Make return pointer defined.
+
+	* debug/vasprintf_chk.c (__vasprintf_chk): Make return pointer defined.
+
 2009-04-29  Jakub Jelinek  <jakub@xxxxxxxxxx>
 
 	* sysdeps/unix/sysv/linux/ifaddrs.c: Revert unintended 2008-08-12
diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c
index bdd3acf..e60a45c 100644
--- a/debug/vasprintf_chk.c
+++ b/debug/vasprintf_chk.c
@@ -49,7 +49,10 @@ __vasprintf_chk (char **result_ptr, int flags, const char *format,
      we know we will never seek on the stream.  */
   string = (char *) malloc (init_string_size);
   if (string == NULL)
-    return -1;
+    {
+      *result_ptr = NULL;
+      return -1;
+    }
 #ifdef _IO_MTSAFE_IO
   sf._sbf._f._lock = NULL;
 #endif
@@ -68,6 +71,7 @@ __vasprintf_chk (char **result_ptr, int flags, const char *format,
   ret = INTUSE(_IO_vfprintf) (&sf._sbf._f, format, args);
   if (ret < 0)
     {
+      *result_ptr = NULL;
       free (sf._sbf._f._IO_buf_base);
       return ret;
     }
diff --git a/libio/vasprintf.c b/libio/vasprintf.c
index 7e15eb0..3051d56 100644
--- a/libio/vasprintf.c
+++ b/libio/vasprintf.c
@@ -51,7 +51,10 @@ _IO_vasprintf (result_ptr, format, args)
      we know we will never seek on the stream.  */
   string = (char *) malloc (init_string_size);
   if (string == NULL)
-    return -1;
+    {
+      *result_ptr = NULL;
+      return -1;
+    }
 #ifdef _IO_MTSAFE_IO
   sf._sbf._f._lock = NULL;
 #endif
@@ -64,6 +67,7 @@ _IO_vasprintf (result_ptr, format, args)
   ret = INTUSE(_IO_vfprintf) (&sf._sbf._f, format, args);
   if (ret < 0)
     {
+      *result_ptr = NULL;
       free (sf._sbf._f._IO_buf_base);
       return ret;
     }


-- 
James Antill -- james@xxxxxxx