You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2007/12/19 03:42:38 UTC
svn commit: r605389 - /incubator/stdcxx/trunk/tests/src/printf.cpp
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 <se...@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);