Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 21091:47f6533674fd legacy-trunk
Use PyOS_vsnprintf() and check its return value.
If it returns -1 (which indicates overflow on old Linux platforms and
perhaps on Windows) or size greater than buffer, write a message
indicating that the previous message was truncated.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Wed, 28 Nov 2001 21:44:53 +0000 |
| parents | e4d380f5f297 |
| children | dd28a4ecb37f |
line wrap: on
line diff
--- a/Python/sysmodule.c Wed Nov 28 21:36:28 2001 +0000 +++ b/Python/sysmodule.c Wed Nov 28 21:44:53 2001 +0000 @@ -1023,12 +1023,19 @@ vfprintf(fp, format, va); else { char buffer[1001]; - if (vsprintf(buffer, format, va) >= sizeof(buffer)) - Py_FatalError("PySys_WriteStdout/err: buffer overrun"); + int written = PyOS_vsnprintf(buffer, sizeof(buffer), + format, va); if (PyFile_WriteString(buffer, file) != 0) { PyErr_Clear(); fputs(buffer, fp); } + if (written == -1 || written > sizeof(buffer)) { + const char *truncated = "... truncated"; + if (PyFile_WriteString(truncated, file) != 0) { + PyErr_Clear(); + fputs(truncated, fp); + } + } } PyErr_Restore(error_type, error_value, error_traceback); }
