Skip to content

Commit d53fe5f

Browse files
bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264)
1 parent 10f8ce6 commit d53fe5f

20 files changed

+35
-35
lines changed

Modules/_collectionsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ tuplegetter_descr_get(PyObject *self, PyObject *obj, PyObject *type)
23882388
return self;
23892389
}
23902390
PyErr_Format(PyExc_TypeError,
2391-
"descriptor for index '%d' for tuple subclasses "
2391+
"descriptor for index '%zd' for tuple subclasses "
23922392
"doesn't apply to '%s' object",
23932393
index,
23942394
obj->ob_type->tp_name);

Modules/_ctypes/callbacks.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ static void _CallPythonObject(void *mem,
165165
if (cnv)
166166
dict = PyType_stgdict(cnv);
167167
else {
168-
PrintError("Getting argument converter %d\n", i);
168+
PrintError("Getting argument converter %zd\n", i);
169169
goto Done;
170170
}
171171

172172
if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) {
173173
PyObject *v = dict->getfunc(*pArgs, dict->size);
174174
if (!v) {
175-
PrintError("create argument %d:\n", i);
175+
PrintError("create argument %zd:\n", i);
176176
Py_DECREF(cnv);
177177
goto Done;
178178
}
@@ -186,14 +186,14 @@ static void _CallPythonObject(void *mem,
186186
/* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */
187187
CDataObject *obj = (CDataObject *)_PyObject_CallNoArg(cnv);
188188
if (!obj) {
189-
PrintError("create argument %d:\n", i);
189+
PrintError("create argument %zd:\n", i);
190190
Py_DECREF(cnv);
191191
goto Done;
192192
}
193193
if (!CDataObject_Check(obj)) {
194194
Py_DECREF(obj);
195195
Py_DECREF(cnv);
196-
PrintError("unexpected result of create argument %d:\n", i);
196+
PrintError("unexpected result of create argument %zd:\n", i);
197197
goto Done;
198198
}
199199
memcpy(obj->b_ptr, *pArgs, dict->size);
@@ -204,7 +204,7 @@ static void _CallPythonObject(void *mem,
204204
} else {
205205
PyErr_SetString(PyExc_TypeError,
206206
"cannot build parameter");
207-
PrintError("Parsing argument %d\n", i);
207+
PrintError("Parsing argument %zd\n", i);
208208
Py_DECREF(cnv);
209209
goto Done;
210210
}

Modules/_ctypes/callproc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,20 +1131,20 @@ PyObject *_ctypes_callproc(PPROC pProc,
11311131
converter = PyTuple_GET_ITEM(argtypes, i);
11321132
v = PyObject_CallFunctionObjArgs(converter, arg, NULL);
11331133
if (v == NULL) {
1134-
_ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
1134+
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
11351135
goto cleanup;
11361136
}
11371137

11381138
err = ConvParam(v, i+1, pa);
11391139
Py_DECREF(v);
11401140
if (-1 == err) {
1141-
_ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
1141+
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
11421142
goto cleanup;
11431143
}
11441144
} else {
11451145
err = ConvParam(arg, i+1, pa);
11461146
if (-1 == err) {
1147-
_ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
1147+
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
11481148
goto cleanup; /* leaking ? */
11491149
}
11501150
}

Modules/_ctypes/malloc_closure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void more_core(void)
7676

7777
#ifdef MALLOC_CLOSURE_DEBUG
7878
printf("block at %p allocated (%d bytes), %d ITEMs\n",
79-
item, count * sizeof(ITEM), count);
79+
item, count * (int)sizeof(ITEM), count);
8080
#endif
8181
/* put them into the free list */
8282
for (i = 0; i < count; ++i) {

Modules/_io/winconsoleio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
725725

726726
if (u8n) {
727727
PyErr_Format(PyExc_SystemError,
728-
"Buffer had room for %d bytes but %d bytes required",
728+
"Buffer had room for %zd bytes but %u bytes required",
729729
len, u8n);
730730
return -1;
731731
}

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ PyLocale_getdefaultlocale(PyObject* self, PyObject *Py_UNUSED(ignored))
392392
char encoding[20];
393393
char locale[100];
394394

395-
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
395+
PyOS_snprintf(encoding, sizeof(encoding), "cp%u", GetACP());
396396

397397
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
398398
LOCALE_SISO639LANGNAME,

Modules/_lzmamodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ parse_filter_spec_lzma(PyObject *spec)
219219

220220
if (lzma_lzma_preset(options, preset)) {
221221
PyMem_Free(options);
222-
PyErr_Format(Error, "Invalid compression preset: %d", preset);
222+
PyErr_Format(Error, "Invalid compression preset: %u", preset);
223223
return NULL;
224224
}
225225

@@ -622,7 +622,7 @@ Compressor_init_alone(lzma_stream *lzs, uint32_t preset, PyObject *filterspecs)
622622
lzma_options_lzma options;
623623

624624
if (lzma_lzma_preset(&options, preset)) {
625-
PyErr_Format(Error, "Invalid compression preset: %d", preset);
625+
PyErr_Format(Error, "Invalid compression preset: %u", preset);
626626
return -1;
627627
}
628628
lzret = lzma_alone_encoder(lzs, &options);

Modules/_multiprocessing/semaphore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
141141
default:
142142
PyErr_Format(PyExc_RuntimeError, "WaitForSingleObject() or "
143143
"WaitForMultipleObjects() gave unrecognized "
144-
"value %d", res);
144+
"value %u", res);
145145
return NULL;
146146
}
147147
}

Modules/_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3347,7 +3347,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
33473347
#if HAVE_ALPN
33483348
if ((size_t)protos->len > UINT_MAX) {
33493349
PyErr_Format(PyExc_OverflowError,
3350-
"protocols longer than %d bytes", UINT_MAX);
3350+
"protocols longer than %u bytes", UINT_MAX);
33513351
return NULL;
33523352
}
33533353

Modules/binascii.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data)
520520
*/
521521
PyErr_Format(Error,
522522
"Invalid base64-encoded string: "
523-
"number of data characters (%d) cannot be 1 more "
523+
"number of data characters (%zd) cannot be 1 more "
524524
"than a multiple of 4",
525525
(bin_data - bin_data_start) / 3 * 4 + 1);
526526
} else {

0 commit comments

Comments
 (0)