bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264)

This commit is contained in:
Serhiy Storchaka 2019-03-13 22:59:55 +02:00 committed by GitHub
parent 10f8ce6688
commit d53fe5f407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 35 additions and 35 deletions

View file

@ -1103,7 +1103,7 @@ get_locale_encoding(char **locale_encoding)
{
#ifdef MS_WINDOWS
char encoding[20];
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
PyOS_snprintf(encoding, sizeof(encoding), "cp%u", GetACP());
#elif defined(__ANDROID__) || defined(__VXWORKS__)
const char *encoding = "UTF-8";
#else

View file

@ -256,7 +256,7 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
This should not happen if called correctly. */
if (theLength == 0) {
message = PyUnicode_FromFormat(
"DLL load failed with error code %d",
"DLL load failed with error code %u",
errorCode);
} else {
/* For some reason a \r\n

View file

@ -372,14 +372,14 @@ vgetargs1_impl(PyObject *compat_args, PyObject *const *stack, Py_ssize_t nargs,
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);
@ -1741,7 +1741,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
else {
PyErr_Format(PyExc_TypeError,
"%.200s%s takes %s %d positional argument%s"
" (%d given)",
" (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
(min != INT_MAX) ? "at most" : "exactly",
@ -1826,7 +1826,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
if (skip) {
PyErr_Format(PyExc_TypeError,
"%.200s%s takes %s %d positional argument%s"
" (%d given)",
" (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
(Py_MIN(pos, min) < i) ? "at least" : "exactly",
@ -2194,7 +2194,7 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
Py_ssize_t min = Py_MIN(pos, parser->min);
PyErr_Format(PyExc_TypeError,
"%.200s%s takes %s %d positional argument%s"
" (%d given)",
" (%zd given)",
(parser->fname == NULL) ? "function" : parser->fname,
(parser->fname == NULL) ? "" : "()",
min < parser->max ? "at least" : "exactly",

View file

@ -2005,7 +2005,7 @@ hamt_node_array_dump(PyHamtNode_Array *node,
goto error;
}
if (_hamt_dump_format(writer, "%d::\n", i)) {
if (_hamt_dump_format(writer, "%zd::\n", i)) {
goto error;
}

View file

@ -160,7 +160,7 @@ PyArena_Free(PyArena *arena)
#if defined(Py_DEBUG)
/*
fprintf(stderr,
"alloc=%d size=%d blocks=%d block_size=%d big=%d objects=%d\n",
"alloc=%zu size=%zu blocks=%zu block_size=%zu big=%zu objects=%zu\n",
arena->total_allocs, arena->total_size, arena->total_blocks,
arena->total_block_size, arena->total_big_blocks,
PyList_Size(arena->a_objects));