Skip to content

Commit 783bed4

Browse files
[3.7] bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264). (GH-12322)
(cherry picked from commit d53fe5f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent a84f9bc commit 783bed4

File tree

18 files changed

+34
-34
lines changed

18 files changed

+34
-34
lines changed

Modules/_ctypes/callbacks.c

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

167167
if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) {
168168
PyObject *v = dict->getfunc(*pArgs, dict->size);
169169
if (!v) {
170-
PrintError("create argument %d:\n", i);
170+
PrintError("create argument %zd:\n", i);
171171
Py_DECREF(cnv);
172172
goto Done;
173173
}
@@ -181,14 +181,14 @@ static void _CallPythonObject(void *mem,
181181
/* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */
182182
CDataObject *obj = (CDataObject *)_PyObject_CallNoArg(cnv);
183183
if (!obj) {
184-
PrintError("create argument %d:\n", i);
184+
PrintError("create argument %zd:\n", i);
185185
Py_DECREF(cnv);
186186
goto Done;
187187
}
188188
if (!CDataObject_Check(obj)) {
189189
Py_DECREF(obj);
190190
Py_DECREF(cnv);
191-
PrintError("unexpected result of create argument %d:\n", i);
191+
PrintError("unexpected result of create argument %zd:\n", i);
192192
goto Done;
193193
}
194194
memcpy(obj->b_ptr, *pArgs, dict->size);
@@ -199,7 +199,7 @@ static void _CallPythonObject(void *mem,
199199
} else {
200200
PyErr_SetString(PyExc_TypeError,
201201
"cannot build parameter");
202-
PrintError("Parsing argument %d\n", i);
202+
PrintError("Parsing argument %zd\n", i);
203203
Py_DECREF(cnv);
204204
goto Done;
205205
}

Modules/_ctypes/callproc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,20 +1125,20 @@ PyObject *_ctypes_callproc(PPROC pProc,
11251125
converter = PyTuple_GET_ITEM(argtypes, i);
11261126
v = PyObject_CallFunctionObjArgs(converter, arg, NULL);
11271127
if (v == NULL) {
1128-
_ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
1128+
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
11291129
goto cleanup;
11301130
}
11311131

11321132
err = ConvParam(v, i+1, pa);
11331133
Py_DECREF(v);
11341134
if (-1 == err) {
1135-
_ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
1135+
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
11361136
goto cleanup;
11371137
}
11381138
} else {
11391139
err = ConvParam(arg, i+1, pa);
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; /* leaking ? */
11431143
}
11441144
}

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
@@ -724,7 +724,7 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
724724

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

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ PyLocale_getdefaultlocale(PyObject* self)
394394
char encoding[100];
395395
char locale[100];
396396

397-
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
397+
PyOS_snprintf(encoding, sizeof(encoding), "cp%u", GetACP());
398398

399399
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
400400
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

@@ -630,7 +630,7 @@ Compressor_init_alone(lzma_stream *lzs, uint32_t preset, PyObject *filterspecs)
630630
lzma_options_lzma options;
631631

632632
if (lzma_lzma_preset(&options, preset)) {
633-
PyErr_Format(Error, "Invalid compression preset: %d", preset);
633+
PyErr_Format(Error, "Invalid compression preset: %u", preset);
634634
return -1;
635635
}
636636
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
@@ -3348,7 +3348,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
33483348
#if HAVE_ALPN
33493349
if ((size_t)protos->len > UINT_MAX) {
33503350
PyErr_Format(PyExc_OverflowError,
3351-
"protocols longer than %d bytes", UINT_MAX);
3351+
"protocols longer than %u bytes", UINT_MAX);
33523352
return NULL;
33533353
}
33543354

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 {

Modules/socketmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,7 +4102,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
41024102
break;
41034103
default:
41044104
PyErr_Format(PyExc_TypeError,
4105-
"sendto() takes 2 or 3 arguments (%d given)",
4105+
"sendto() takes 2 or 3 arguments (%zd given)",
41064106
arglen);
41074107
return NULL;
41084108
}
@@ -4642,7 +4642,7 @@ sock_ioctl(PySocketSockObject *s, PyObject *arg)
46424642
return PyLong_FromUnsignedLong(recv); }
46434643
#endif
46444644
default:
4645-
PyErr_Format(PyExc_ValueError, "invalid ioctl command %d", cmd);
4645+
PyErr_Format(PyExc_ValueError, "invalid ioctl command %lu", cmd);
46464646
return NULL;
46474647
}
46484648
}

0 commit comments

Comments
 (0)