diff options
author | Guido van Rossum <guido@python.org> | 1998-10-12 18:22:10 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-10-12 18:22:10 (GMT) |
commit | 8442af35fe337a81efa83952574c5ca0dbcc2883 (patch) | |
tree | a1f0bfbe09358c14ed0653485e60c0f72216724b /Python/sysmodule.c | |
parent | 41f0a98f8f22d37ce721aa0a5d4285b3e4b2e7d7 (diff) | |
download | cpython-8442af35fe337a81efa83952574c5ca0dbcc2883.zip cpython-8442af35fe337a81efa83952574c5ca0dbcc2883.tar.gz cpython-8442af35fe337a81efa83952574c5ca0dbcc2883.tar.bz2 |
Patches for mywrite() by Marc Lemburg: save/restore the error state
reliably; check return value of vsprintf().
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 29e55ea..6c834d0 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -594,8 +594,7 @@ PySys_SetArgv(argc, argv) The first function writes to sys.stdout; the second to sys.stderr. When there is a problem, they write to the real (C level) stdout or stderr; - no exceptions are raised (but a pending exception may be cleared when a - new exception is caught). + no exceptions are raised. Both take a printf-style format string as their first argument followed by a variable length argument list determined by the format string. @@ -619,18 +618,22 @@ mywrite(name, fp, format, va) va_list va; { PyObject *file; + PyObject *error_type, *error_value, *error_traceback; + PyErr_Fetch(&error_type, &error_value, &error_traceback); file = PySys_GetObject(name); if (file == NULL || PyFile_AsFile(file) == fp) vfprintf(fp, format, va); else { char buffer[1001]; - vsprintf(buffer, format, va); + if (vsprintf(buffer, format, va) >= sizeof(buffer)) + Py_FatalError("PySys_WriteStdout/err: buffer overrun"); if (PyFile_WriteString(buffer, file) != 0) { PyErr_Clear(); fputs(buffer, fp); } } + PyErr_Restore(error_type, error_value, error_traceback); } void |