summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-12-03 00:43:33 +0000
committerTim Peters <tim.peters@gmail.com>2001-12-03 00:43:33 +0000
commit348ba13fa5c8bdc3b7ae8ae59b4aeeab8f48fe0e (patch)
treefb6a2735b66f7960d650300b13fc8072921d0a62 /Python/sysmodule.c
parent99d0767009def8b131a0f3bd642fe155c5818b40 (diff)
downloadcpython-348ba13fa5c8bdc3b7ae8ae59b4aeeab8f48fe0e.tar.gz
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c9
1 files changed, 1 insertions, 8 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index faa63ab7a3..ff49adcece 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1025,18 +1025,11 @@ mywrite(char *name, FILE *fp, const char *format, va_list va)
char buffer[1001];
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 (trouble) {
+ if (written < 0 || written >= sizeof(buffer)) {
const char *truncated = "... truncated";
if (PyFile_WriteString(truncated, file) != 0) {
PyErr_Clear();