Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 21145:87fa6e9bd77e legacy-trunk
mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
use wrappers on all platforms, to make this as consistent as possible x-
platform (in particular, make sure there's at least one \0 byte in
the output buffer). Also document more of the truth about what these do.
getargs.c, seterror(): Three computations of remaining buffer size were
backwards, thus telling PyOS_snprintf the buffer is larger than it
actually is. This matters a lot now that PyOS_snprintf ensures there's a
trailing \0 byte (because it didn't get the truth about the buffer size,
it was storing \0 beyond the true end of the buffer).
sysmodule.c, mywrite(): Simplify, now that PyOS_vsnprintf guarantees to
produce a \0 byte.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Mon, 03 Dec 2001 00:43:33 +0000 |
| parents | dd28a4ecb37f |
| children | c64fc56f6072 |
comparison
equal
deleted
inserted
replaced
| 21144:96a08fd38ef8 | 21145:87fa6e9bd77e |
|---|---|
| 1023 vfprintf(fp, format, va); | 1023 vfprintf(fp, format, va); |
| 1024 else { | 1024 else { |
| 1025 char buffer[1001]; | 1025 char buffer[1001]; |
| 1026 const int written = PyOS_vsnprintf(buffer, sizeof(buffer), | 1026 const int written = PyOS_vsnprintf(buffer, sizeof(buffer), |
| 1027 format, va); | 1027 format, va); |
| 1028 const int trouble = written < 0 || written >= sizeof(buffer); | |
| 1029 if (trouble) { | |
| 1030 /* Ensure there's a trailing null byte -- MS | |
| 1031 vsnprintf fills the buffer to the very end | |
| 1032 if it's not big enough. */ | |
| 1033 buffer[sizeof(buffer) - 1] = '\0'; | |
| 1034 } | |
| 1035 if (PyFile_WriteString(buffer, file) != 0) { | 1028 if (PyFile_WriteString(buffer, file) != 0) { |
| 1036 PyErr_Clear(); | 1029 PyErr_Clear(); |
| 1037 fputs(buffer, fp); | 1030 fputs(buffer, fp); |
| 1038 } | 1031 } |
| 1039 if (trouble) { | 1032 if (written < 0 || written >= sizeof(buffer)) { |
| 1040 const char *truncated = "... truncated"; | 1033 const char *truncated = "... truncated"; |
| 1041 if (PyFile_WriteString(truncated, file) != 0) { | 1034 if (PyFile_WriteString(truncated, file) != 0) { |
| 1042 PyErr_Clear(); | 1035 PyErr_Clear(); |
| 1043 fputs(truncated, fp); | 1036 fputs(truncated, fp); |
| 1044 } | 1037 } |
