summaryrefslogtreecommitdiff
path: root/pyfstream.h
diff options
context:
space:
mode:
Diffstat (limited to 'pyfstream.h')
-rw-r--r--pyfstream.h8
1 files changed, 6 insertions, 2 deletions
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;
}
};