From 534a98e6c215e118a77403a7d7306e16aae2a7e6 Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Mon, 30 Mar 2026 08:05:38 +0800 Subject: [PATCH 1/2] Fix format specifiers in error messages for watcher and size checks --- Modules/_testcapi/watchers.c | 4 ++-- Modules/_testcapimodule.c | 4 ++-- Modules/_testinternalcapi.c | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c index 6d061bb8d51040..5a756a87c15fe9 100644 --- a/Modules/_testcapi/watchers.c +++ b/Modules/_testcapi/watchers.c @@ -364,7 +364,7 @@ add_code_watcher(PyObject *self, PyObject *which_watcher) watcher_id = PyCode_AddWatcher(error_code_event_handler); } else { - PyErr_Format(PyExc_ValueError, "invalid watcher %d", which_l); + PyErr_Format(PyExc_ValueError, "invalid watcher %ld", which_l); return NULL; } if (watcher_id < 0) { @@ -673,7 +673,7 @@ add_context_watcher(PyObject *self, PyObject *which_watcher) assert(PyLong_Check(which_watcher)); long which_l = PyLong_AsLong(which_watcher); if (which_l < 0 || which_l >= (long)Py_ARRAY_LENGTH(callbacks)) { - PyErr_Format(PyExc_ValueError, "invalid watcher %d", which_l); + PyErr_Format(PyExc_ValueError, "invalid watcher %ld", which_l); return NULL; } int watcher_id = PyContext_AddWatcher(callbacks[which_l]); diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index a76af1416e091f..aa12db20908b97 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -116,8 +116,8 @@ test_sizeof_c_types(PyObject *self, PyObject *Py_UNUSED(ignored)) do { \ if (EXPECTED != sizeof(TYPE)) { \ PyErr_Format(get_testerror(self), \ - "sizeof(%s) = %u instead of %u", \ - #TYPE, sizeof(TYPE), EXPECTED); \ + "sizeof(%s) = %zu instead of %u", \ + #TYPE, sizeof(TYPE), (unsigned)(EXPECTED)); \ return (PyObject*)NULL; \ } \ } while (0) diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 7f6ea621f87145..58a400a4ab0d06 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -417,14 +417,14 @@ test_bswap(PyObject *self, PyObject *Py_UNUSED(args)) uint16_t u16 = _Py_bswap16(UINT16_C(0x3412)); if (u16 != UINT16_C(0x1234)) { PyErr_Format(PyExc_AssertionError, - "_Py_bswap16(0x3412) returns %u", u16); + "_Py_bswap16(0x3412) returns %d", u16); return NULL; } uint32_t u32 = _Py_bswap32(UINT32_C(0x78563412)); if (u32 != UINT32_C(0x12345678)) { PyErr_Format(PyExc_AssertionError, - "_Py_bswap32(0x78563412) returns %lu", u32); + "_Py_bswap32(0x78563412) returns %u", u32); return NULL; } @@ -711,7 +711,7 @@ check_bytes_find(const char *haystack0, const char *needle0, needle0, len_needle, offset); if (result_1 != expected) { PyErr_Format(PyExc_AssertionError, - "Incorrect result_1: '%s' in '%s' (offset=%zd)", + "Incorrect result_1: '%s' in '%s' (offset=%d)", needle0, haystack0, offset); return -1; } @@ -735,7 +735,7 @@ check_bytes_find(const char *haystack0, const char *needle0, PyMem_Free(needle); if (result_2 != expected) { PyErr_Format(PyExc_AssertionError, - "Incorrect result_2: '%s' in '%s' (offset=%zd)", + "Incorrect result_2: '%s' in '%s' (offset=%d)", needle0, haystack0, offset); return -1; } @@ -1158,7 +1158,7 @@ get_interp_settings(PyObject *self, PyObject *args) } else { PyErr_Format(PyExc_NotImplementedError, - "%zd", interpid); + "%d", interpid); return NULL; } assert(interp != NULL); From b5feea27c7d40c1203f8f8d926e2092e03eee2db Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Mon, 30 Mar 2026 22:09:09 +0800 Subject: [PATCH 2/2] Fix format specifiers in check_bytes_find for offset parameter --- Modules/_testinternalcapi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 58a400a4ab0d06..c00bad46a54907 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -703,7 +703,7 @@ test_edit_cost(PyObject *self, PyObject *Py_UNUSED(args)) static int check_bytes_find(const char *haystack0, const char *needle0, - int offset, Py_ssize_t expected) + Py_ssize_t offset, Py_ssize_t expected) { Py_ssize_t len_haystack = strlen(haystack0); Py_ssize_t len_needle = strlen(needle0); @@ -711,7 +711,7 @@ check_bytes_find(const char *haystack0, const char *needle0, needle0, len_needle, offset); if (result_1 != expected) { PyErr_Format(PyExc_AssertionError, - "Incorrect result_1: '%s' in '%s' (offset=%d)", + "Incorrect result_1: '%s' in '%s' (offset=%zd)", needle0, haystack0, offset); return -1; } @@ -735,7 +735,7 @@ check_bytes_find(const char *haystack0, const char *needle0, PyMem_Free(needle); if (result_2 != expected) { PyErr_Format(PyExc_AssertionError, - "Incorrect result_2: '%s' in '%s' (offset=%d)", + "Incorrect result_2: '%s' in '%s' (offset=%zd)", needle0, haystack0, offset); return -1; }