[3.7] bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264). (GH-12322)
(cherry picked from commit d53fe5f407ff4b529628b01a1bcbf21a6aad5c3a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Python/getargs.c b/Python/getargs.c
index 992cb21..73e47f8 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -371,14 +371,14 @@
if (nargs < min || max < nargs) {
if (message == NULL)
PyErr_Format(PyExc_TypeError,
- "%.150s%s takes %s %d argument%s (%ld given)",
+ "%.150s%s takes %s %d argument%s (%zd given)",
fname==NULL ? "function" : fname,
fname==NULL ? "" : "()",
min==max ? "exactly"
: nargs < min ? "at least" : "at most",
nargs < min ? min : max,
(nargs < min ? min : max) == 1 ? "" : "s",
- Py_SAFE_DOWNCAST(nargs, Py_ssize_t, long));
+ nargs);
else
PyErr_SetString(PyExc_TypeError, message);
return cleanreturn(0, &freelist);
@@ -1718,7 +1718,7 @@
else {
PyErr_Format(PyExc_TypeError,
"%.200s%s takes %s %d positional arguments"
- " (%d given)",
+ " (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
(min != INT_MAX) ? "at most" : "exactly",
@@ -1797,7 +1797,7 @@
if (skip) {
PyErr_Format(PyExc_TypeError,
"%.200s%s takes %s %d positional arguments"
- " (%d given)",
+ " (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
(Py_MIN(pos, min) < i) ? "at least" : "exactly",
@@ -2103,7 +2103,7 @@
}
else {
PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional arguments (%d given)",
+ "%.200s%s takes %s %d positional arguments (%zd given)",
(parser->fname == NULL) ? "function" : parser->fname,
(parser->fname == NULL) ? "" : "()",
(parser->min != INT_MAX) ? "at most" : "exactly",
@@ -2152,7 +2152,7 @@
Py_ssize_t min = Py_MIN(pos, parser->min);
PyErr_Format(PyExc_TypeError,
"%.200s%s takes %s %d positional arguments"
- " (%d given)",
+ " (%zd given)",
(parser->fname == NULL) ? "function" : parser->fname,
(parser->fname == NULL) ? "" : "()",
min < parser->max ? "at least" : "exactly",