stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r605389 - /incubator/stdcxx/trunk/tests/src/printf.cpp
Date Wed, 19 Dec 2007 02:42:38 GMT
Author: sebor
Date: Tue Dec 18 18:42:37 2007
New Revision: 605389

URL: http://svn.apache.org/viewvc?rev=605389&view=rev
Log:
2007-12-18  Martin Sebor  <sebor@roguewave.com>

	* printf.cpp (rw_snprintf): NUL-terminated string just like
	snprintf() does.

Modified:
    incubator/stdcxx/trunk/tests/src/printf.cpp

Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/printf.cpp?rev=605389&r1=605388&r2=605389&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Tue Dec 18 18:42:37 2007
@@ -3376,8 +3376,15 @@
 
     va_end (va);
 
-    if (size_t (nchars) <= bufsize)
-        memcpy (buf, tmpbuf, size_t (nchars));
+    if (size_t (nchars) < bufsize) {
+        memcpy (buf, tmpbuf, size_t (nchars + 1 /* NUL */));
+    }
+    else {
+        // buffer isn't big enough
+        memcpy (buf, tmpbuf, bufsize);
+        if (bufsize)
+            buf [bufsize - 1] = '\0';
+    }
 
     free (tmpbuf);
 



Mime
View raw message