From 04c173e762673f96498d4c2a695fc5c3bf5d8106 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Mon, 13 Jan 2020 11:29:58 +0100 Subject: [PATCH 1/2] Remove HAVE_SNPRINTF redefinition on win32 --- Include/pyerrors.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 5125a51ec1aa17..e1427aa835ffed 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -311,11 +311,6 @@ PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( not rely on any particular behavior; eventually the C99 defn may be reliable. */ -#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) -# define HAVE_SNPRINTF -# define snprintf _snprintf -# define vsnprintf _vsnprintf -#endif #include PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) From 768add562d5a2b36c5bb7a0a788dffe0a6c9ebc8 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Mon, 13 Jan 2020 11:34:48 +0100 Subject: [PATCH 2/2] Use PyOS_snprintf instead of snprintf --- Modules/_decimal/_decimal.c | 4 ++-- Modules/socketmodule.c | 1 - Objects/obmalloc.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index e2ac19800315ce..cd1c17ae091261 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -2360,7 +2360,7 @@ dectuple_as_str(PyObject *dectuple) goto error; } - n = snprintf(cp, mem, "%s", sign_special); + n = PyOS_snprintf(cp, mem, "%s", sign_special); if (n < 0 || n >= mem) { PyErr_SetString(PyExc_RuntimeError, "internal error in dec_sequence_as_str"); @@ -2400,7 +2400,7 @@ dectuple_as_str(PyObject *dectuple) if (sign_special[1] == '\0') { /* not a special number */ *cp++ = 'E'; - n = snprintf(cp, MPD_EXPDIGITS+2, "%" PRI_mpd_ssize_t, exp); + n = PyOS_snprintf(cp, MPD_EXPDIGITS+2, "%" PRI_mpd_ssize_t, exp); if (n < 0 || n >= MPD_EXPDIGITS+2) { PyErr_SetString(PyExc_RuntimeError, "internal error in dec_sequence_as_str"); diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index d42fa7ce182934..dcdc3437aeeb86 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -480,7 +480,6 @@ remove_unusable_flags(PyObject *m) #ifdef MS_WIN32 #undef EAFNOSUPPORT #define EAFNOSUPPORT WSAEAFNOSUPPORT -#define snprintf _snprintf #endif #ifndef SOCKETCLOSE diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 3881ff17e06426..db6a3016fdabd5 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -2377,7 +2377,7 @@ _PyMem_DebugCheckAddress(char api, const void *p) id = (char)q[-SST]; if (id != api) { msg = msgbuf; - snprintf(msgbuf, sizeof(msgbuf), "bad ID: Allocated using API '%c', verified using API '%c'", id, api); + PyOS_snprintf(msgbuf, sizeof(msgbuf), "bad ID: Allocated using API '%c', verified using API '%c'", id, api); msgbuf[sizeof(msgbuf)-1] = 0; goto error; }