summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-12-02 08:29:16 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-12-02 08:29:16 (GMT)
commit080d5b3f0ba3a21811e3d3de35d4f8aa7cf408ad (patch)
tree4fad2e520935d927f10184e4d8a1d3c2be8dfd6a /Python/sysmodule.c
parent64be0b4aa5094d3a1a85eba20fcc9b7fca3289a9 (diff)
downloadcpython-080d5b3f0ba3a21811e3d3de35d4f8aa7cf408ad.zip
cpython-080d5b3f0ba3a21811e3d3de35d4f8aa7cf408ad.tar.gz
cpython-080d5b3f0ba3a21811e3d3de35d4f8aa7cf408ad.tar.bz2
mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
ends. Also, when there is trouble, ensure the buffer has a traiing 0 byte.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 8b27b37..faa63ab 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1023,13 +1023,20 @@ mywrite(char *name, FILE *fp, const char *format, va_list va)
vfprintf(fp, format, va);
else {
char buffer[1001];
- int written = PyOS_vsnprintf(buffer, sizeof(buffer),
- format, va);
+ const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
+ format, va);
+ const int trouble = written < 0 || written >= sizeof(buffer);
+ if (trouble) {
+ /* Ensure there's a trailing null byte -- MS
+ vsnprintf fills the buffer to the very end
+ if it's not big enough. */
+ buffer[sizeof(buffer) - 1] = '\0';
+ }
if (PyFile_WriteString(buffer, file) != 0) {
PyErr_Clear();
fputs(buffer, fp);
}
- if (written == -1 || written > sizeof(buffer)) {
+ if (trouble) {
const char *truncated = "... truncated";
if (PyFile_WriteString(truncated, file) != 0) {
PyErr_Clear();