From 96fcf41a405c5f77ea0020962f367901fd646a01 Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Mon, 30 Mar 2026 08:07:31 +0800 Subject: [PATCH 1/3] Fix format specifiers in error messages across multiple modules --- Modules/_asynciomodule.c | 6 +++--- Modules/_remote_debugging/asyncio.c | 2 +- Modules/_ssl.c | 6 +++--- Modules/_zoneinfo.c | 2 +- Modules/_zstd/compressor.c | 4 ++-- Modules/binascii.c | 4 ++-- Modules/socketmodule.c | 3 +-- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 826c0b25a362c2..bd294648ca222f 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -2244,7 +2244,7 @@ enter_task(_PyThreadStateImpl *ts, PyObject *loop, PyObject *task) PyExc_RuntimeError, "Cannot enter into task %R while another " \ "task %R is being executed.", - task, ts->asyncio_running_task, NULL); + task, ts->asyncio_running_task); return -1; } @@ -2265,7 +2265,7 @@ leave_task(_PyThreadStateImpl *ts, PyObject *loop, PyObject *task) PyExc_RuntimeError, "Invalid attempt to leave task %R while " \ "task %R is entered.", - task, ts->asyncio_running_task ? ts->asyncio_running_task : Py_None, NULL); + task, ts->asyncio_running_task ? ts->asyncio_running_task : Py_None); return -1; } Py_CLEAR(ts->asyncio_running_task); @@ -2328,7 +2328,7 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, self->task_log_destroy_pending = 0; PyErr_Format(PyExc_TypeError, "a coroutine was expected, got %R", - coro, NULL); + coro); return -1; } diff --git a/Modules/_remote_debugging/asyncio.c b/Modules/_remote_debugging/asyncio.c index 12a8a9acc13bac..263c502a857004 100644 --- a/Modules/_remote_debugging/asyncio.c +++ b/Modules/_remote_debugging/asyncio.c @@ -212,7 +212,7 @@ parse_task_name( set_exception_cause(unwinder, PyExc_RuntimeError, "Task name PyLong parsing failed"); return NULL; } - return PyUnicode_FromFormat("Task-%d", res); + return PyUnicode_FromFormat("Task-%ld", res); } if(!(GET_MEMBER(unsigned long, type_obj, unwinder->debug_offsets.type_object.tp_flags) & Py_TPFLAGS_UNICODE_SUBCLASS)) { diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 6f75af861135d6..797483542ee691 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -592,7 +592,7 @@ fill_and_set_sslerror(_sslmodulestate *state, } else { if (PyUnicodeWriter_Format( - writer, "unknown error (0x%x)", errcode) < 0) { + writer, "unknown error (0x%lx)", errcode) < 0) { goto fail; } } @@ -4059,7 +4059,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what) break; default: PyErr_Format(PyExc_ValueError, - "Unsupported TLS/SSL version 0x%x", v); + "Unsupported TLS/SSL version 0x%lx", v); return -1; } @@ -4093,7 +4093,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what) } if (result == 0) { PyErr_Format(PyExc_ValueError, - "Unsupported protocol version 0x%x", v); + "Unsupported protocol version 0x%lx", v); return -1; } return 0; diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 159cac3c06601a..aa0b1302cb2fc6 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -991,7 +991,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj) } if (!PyTuple_CheckExact(data_tuple)) { - PyErr_Format(PyExc_TypeError, "Invalid data result type: %r", + PyErr_Format(PyExc_TypeError, "Invalid data result type: %R", data_tuple); goto error; } diff --git a/Modules/_zstd/compressor.c b/Modules/_zstd/compressor.c index f90bc9c5ab58b1..8a3cd182ab1516 100644 --- a/Modules/_zstd/compressor.c +++ b/Modules/_zstd/compressor.c @@ -74,7 +74,7 @@ zstd_contentsize_converter(PyObject *size, unsigned long long *p) if (PyErr_ExceptionMatches(PyExc_OverflowError)) { PyErr_Format(PyExc_ValueError, "size argument should be a positive int less " - "than %ull", ZSTD_CONTENTSIZE_ERROR); + "than %llu", ZSTD_CONTENTSIZE_ERROR); return 0; } return 0; @@ -83,7 +83,7 @@ zstd_contentsize_converter(PyObject *size, unsigned long long *p) *p = ZSTD_CONTENTSIZE_ERROR; PyErr_Format(PyExc_ValueError, "size argument should be a positive int less " - "than %ull", ZSTD_CONTENTSIZE_ERROR); + "than %llu", ZSTD_CONTENTSIZE_ERROR); return 0; } *p = pledged_size; diff --git a/Modules/binascii.c b/Modules/binascii.c index dbe77ff248d34e..c51bb9c3c77371 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -1350,7 +1350,7 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data, state = get_binascii_state(module); if (state != NULL) { PyErr_Format(state->Error, - "Base85 overflow in hunk starting at byte %d", + "Base85 overflow in hunk starting at byte %zd", (data->len - ascii_len) / 5 * 5); } goto error; @@ -1361,7 +1361,7 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data, else { state = get_binascii_state(module); if (state != NULL) { - PyErr_Format(state->Error, "bad Base85 character at position %d", + PyErr_Format(state->Error, "bad Base85 character at position %zd", data->len - ascii_len); } goto error; diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 1cedd64e0e9953..a97b09a4f5df0e 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3357,8 +3357,7 @@ sock_setsockopt(PyObject *self, PyObject *args) arglen = PyTuple_Size(args); if (arglen == 3 && optval == Py_None) { PyErr_Format(PyExc_TypeError, - "setsockopt() requires 4 arguments when the third argument is None", - arglen); + "setsockopt() requires 4 arguments when the third argument is None"); return NULL; } if (arglen == 4 && optval != Py_None) { From 36774bee9f37b4e6c9cdbf7505a558ce033d8215 Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Mon, 30 Mar 2026 22:43:16 +0800 Subject: [PATCH 2/3] prefer another PR to fix --- Modules/_zstd/compressor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_zstd/compressor.c b/Modules/_zstd/compressor.c index 8a3cd182ab1516..f90bc9c5ab58b1 100644 --- a/Modules/_zstd/compressor.c +++ b/Modules/_zstd/compressor.c @@ -74,7 +74,7 @@ zstd_contentsize_converter(PyObject *size, unsigned long long *p) if (PyErr_ExceptionMatches(PyExc_OverflowError)) { PyErr_Format(PyExc_ValueError, "size argument should be a positive int less " - "than %llu", ZSTD_CONTENTSIZE_ERROR); + "than %ull", ZSTD_CONTENTSIZE_ERROR); return 0; } return 0; @@ -83,7 +83,7 @@ zstd_contentsize_converter(PyObject *size, unsigned long long *p) *p = ZSTD_CONTENTSIZE_ERROR; PyErr_Format(PyExc_ValueError, "size argument should be a positive int less " - "than %llu", ZSTD_CONTENTSIZE_ERROR); + "than %ull", ZSTD_CONTENTSIZE_ERROR); return 0; } *p = pledged_size; From f16838e332be43d73ff1a005ba1e261a9597ff95 Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Mon, 30 Mar 2026 23:03:03 +0800 Subject: [PATCH 3/3] resolve comments --- Modules/_ssl.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 797483542ee691..2145705b7b8b6c 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -4016,15 +4016,11 @@ _ssl__SSLContext_verify_flags_set_impl(PySSLContext *self, PyObject *value) static int set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what) { - long v; + int v; int result; - if (!PyArg_Parse(arg, "l", &v)) + if (!PyArg_Parse(arg, "i", &v)) return -1; - if (v > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "Option is too long"); - return -1; - } switch(self->protocol) { case PY_SSL_VERSION_TLS_CLIENT: _Py_FALLTHROUGH; @@ -4059,7 +4055,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what) break; default: PyErr_Format(PyExc_ValueError, - "Unsupported TLS/SSL version 0x%lx", v); + "Unsupported TLS/SSL version 0x%x", (unsigned)v); return -1; } @@ -4093,7 +4089,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what) } if (result == 0) { PyErr_Format(PyExc_ValueError, - "Unsupported protocol version 0x%lx", v); + "Unsupported protocol version 0x%x", (unsigned)v); return -1; } return 0;