Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 21090:5e25c669741c | 21091:47f6533674fd |
|---|---|
| 1021 file = PySys_GetObject(name); | 1021 file = PySys_GetObject(name); |
| 1022 if (file == NULL || PyFile_AsFile(file) == fp) | 1022 if (file == NULL || PyFile_AsFile(file) == fp) |
| 1023 vfprintf(fp, format, va); | 1023 vfprintf(fp, format, va); |
| 1024 else { | 1024 else { |
| 1025 char buffer[1001]; | 1025 char buffer[1001]; |
| 1026 if (vsprintf(buffer, format, va) >= sizeof(buffer)) | 1026 int written = PyOS_vsnprintf(buffer, sizeof(buffer), |
| 1027 Py_FatalError("PySys_WriteStdout/err: buffer overrun"); | 1027 format, va); |
| 1028 if (PyFile_WriteString(buffer, file) != 0) { | 1028 if (PyFile_WriteString(buffer, file) != 0) { |
| 1029 PyErr_Clear(); | 1029 PyErr_Clear(); |
| 1030 fputs(buffer, fp); | 1030 fputs(buffer, fp); |
| 1031 } | 1031 } |
| 1032 if (written == -1 || written > sizeof(buffer)) { | |
| 1033 const char *truncated = "... truncated"; | |
| 1034 if (PyFile_WriteString(truncated, file) != 0) { | |
| 1035 PyErr_Clear(); | |
| 1036 fputs(truncated, fp); | |
| 1037 } | |
| 1038 } | |
| 1032 } | 1039 } |
| 1033 PyErr_Restore(error_type, error_value, error_traceback); | 1040 PyErr_Restore(error_type, error_value, error_traceback); |
| 1034 } | 1041 } |
| 1035 | 1042 |
| 1036 void | 1043 void |
