From 7eafc0d9cad27ac74db529b7eab360e5950835eb Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 15 Feb 2005 10:53:29 +0000 Subject: bug fix --- pyfstream.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pyfstream.h') diff --git a/pyfstream.h b/pyfstream.h index e10b5bd5..c41940f5 100644 --- a/pyfstream.h +++ b/pyfstream.h @@ -35,8 +35,12 @@ class pyoutbuf : public std::streambuf { // write multiple characters virtual std::streamsize xsputn (const char* s, std::streamsize num) { - if (PyFile_WriteString(s, (PyObject *)fo) < 0) - return 0; + char * buf = new char[num + 1]; + std::strncpy(buf, s, num); + buf[num] = '\0'; + if (PyFile_WriteString(buf, (PyObject *)fo) < 0) + num = 0; + delete[] buf; return num; } }; -- cgit v1.2.3