From: Ben Pfaff <blp@gnu.org>
Date: Mon, 17 Apr 2006 03:36:40 +0000 (+0000)
Subject: Make ds_vprintf() properly handle a null string.
X-Git-Tag: sav-api~1981
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a621b4a73d06d73a753c9f7207c03393dfb1b81e;p=pspp

Make ds_vprintf() properly handle a null string.
---

diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog
index ff8d321e5b..2c80db58c3 100644
--- a/src/libpspp/ChangeLog
+++ b/src/libpspp/ChangeLog
@@ -1,3 +1,8 @@
+Sun Apr 16 20:33:19 2006  Ben Pfaff  <blp@gnu.org>
+
+	* str.c (ds_vprintf): Don't try to write into the string if it is
+	null.
+
 Sun Apr 16 18:52:41 2006  Ben Pfaff  <blp@gnu.org>
 
 	GNU standards require "file name" instead of "filename" in
diff --git a/src/libpspp/str.c b/src/libpspp/str.c
index c72f19969e..c8497c34af 100644
--- a/src/libpspp/str.c
+++ b/src/libpspp/str.c
@@ -704,7 +704,7 @@ ds_vprintf (struct string *st, const char *format, va_list args_)
 #endif
 
   va_copy (args, args_);
-  avail = st->capacity - st->length + 1;
+  avail = st->string != NULL ? st->capacity - st->length + 1 : 0;
   needed = vsnprintf (st->string + st->length, avail, format, args);
   va_end (args);