Skip to content

Commit 706768c

Browse files
committed
Issue #22156: Fix some "comparison between signed and unsigned integers"
compiler warnings in the Modules/ subdirectory.
1 parent 12174a5 commit 706768c

13 files changed

Lines changed: 24 additions & 21 deletions

File tree

Modules/_bz2module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
188188
if (action == BZ_FINISH && bzerror == BZ_STREAM_END)
189189
break;
190190
}
191-
if (data_size != PyBytes_GET_SIZE(result))
191+
if (data_size != (size_t)PyBytes_GET_SIZE(result))
192192
if (_PyBytes_Resize(&result, data_size) < 0)
193193
goto error;
194194
return result;
@@ -457,7 +457,7 @@ decompress(BZ2Decompressor *d, char *data, size_t len)
457457
d->bzs.avail_out = (unsigned int)Py_MIN(buffer_left, UINT_MAX);
458458
}
459459
}
460-
if (data_size != PyBytes_GET_SIZE(result))
460+
if (data_size != (size_t)PyBytes_GET_SIZE(result))
461461
if (_PyBytes_Resize(&result, data_size) < 0)
462462
goto error;
463463
return result;

Modules/_csv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ dialect_check_quoting(int quoting)
290290
StyleDesc *qs;
291291

292292
for (qs = quote_styles; qs->name; qs++) {
293-
if (qs->style == quoting)
293+
if ((int)qs->style == quoting)
294294
return 0;
295295
}
296296
PyErr_Format(PyExc_TypeError, "bad \"quoting\" value");

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ resize(PyObject *self, PyObject *args)
16061606
"Memory cannot be resized because this object doesn't own it");
16071607
return NULL;
16081608
}
1609-
if (size <= sizeof(obj->b_value)) {
1609+
if ((size_t)size <= sizeof(obj->b_value)) {
16101610
/* internal default buffer is large enough */
16111611
obj->b_size = size;
16121612
goto done;

Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3741,7 +3741,7 @@ PyInit__elementtree(void)
37413741
if (expat_capi) {
37423742
/* check that it's usable */
37433743
if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 ||
3744-
expat_capi->size < sizeof(struct PyExpat_CAPI) ||
3744+
(size_t)expat_capi->size < sizeof(struct PyExpat_CAPI) ||
37453745
expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION ||
37463746
expat_capi->MINOR_VERSION != XML_MINOR_VERSION ||
37473747
expat_capi->MICRO_VERSION != XML_MICRO_VERSION) {

Modules/_io/bytesio.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,20 @@ unshare(bytesio *self, size_t preferred_size, int truncate)
5353
Py_ssize_t copy_size;
5454
char *new_buf;
5555

56-
if((! truncate) && preferred_size < self->string_size) {
56+
if((! truncate) && preferred_size < (size_t)self->string_size) {
5757
preferred_size = self->string_size;
5858
}
5959

60+
/* PyMem_Malloc() returns NULL if preferred_size is bigger
61+
than PY_SSIZE_T_MAX */
6062
new_buf = (char *)PyMem_Malloc(preferred_size);
6163
if (new_buf == NULL) {
6264
PyErr_NoMemory();
6365
return -1;
6466
}
6567

6668
copy_size = self->string_size;
67-
if (copy_size > preferred_size) {
69+
if ((size_t)copy_size > preferred_size) {
6870
copy_size = preferred_size;
6971
}
7072

Modules/_io/textio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ _PyIO_find_line_ending(
17301730
else {
17311731
/* Non-universal mode. */
17321732
Py_ssize_t readnl_len = PyUnicode_GET_LENGTH(readnl);
1733-
char *nl = PyUnicode_DATA(readnl);
1733+
Py_UCS1 *nl = PyUnicode_1BYTE_DATA(readnl);
17341734
/* Assume that readnl is an ASCII character. */
17351735
assert(PyUnicode_KIND(readnl) == PyUnicode_1BYTE_KIND);
17361736
if (readnl_len == 1) {

Modules/_sre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ pattern_repr(PatternObject *obj)
12361236
};
12371237
PyObject *result = NULL;
12381238
PyObject *flag_items;
1239-
int i;
1239+
size_t i;
12401240
int flags = obj->flags;
12411241

12421242
/* Omit re.UNICODE for valid string patterns. */

Modules/_struct.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,8 @@ prepare_s(PyStructObject *self)
12631263
const char *s;
12641264
const char *fmt;
12651265
char c;
1266-
Py_ssize_t size, len, ncodes, num, itemsize;
1266+
Py_ssize_t size, len, num, itemsize;
1267+
size_t ncodes;
12671268

12681269
fmt = PyBytes_AS_STRING(self->s_format);
12691270

@@ -1319,7 +1320,7 @@ prepare_s(PyStructObject *self)
13191320
}
13201321

13211322
/* check for overflow */
1322-
if ((ncodes + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) {
1323+
if ((ncodes + 1) > ((size_t)PY_SSIZE_T_MAX / sizeof(formatcode))) {
13231324
PyErr_NoMemory();
13241325
return -1;
13251326
}

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ test_long_numbits(PyObject *self)
17191719
{-0xffffL, 16, -1},
17201720
{0xfffffffL, 28, 1},
17211721
{-0xfffffffL, 28, -1}};
1722-
int i;
1722+
size_t i;
17231723

17241724
for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) {
17251725
size_t nbits;

Modules/_tkinter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ varname_converter(PyObject *in, void *_out)
14141414
return 0;
14151415
}
14161416
s = PyBytes_AsString(in);
1417-
if (strlen(s) != PyBytes_Size(in)) {
1417+
if (strlen(s) != (size_t)PyBytes_Size(in)) {
14181418
PyErr_SetString(PyExc_ValueError, "null byte in bytes object");
14191419
return 0;
14201420
}
@@ -1431,7 +1431,7 @@ varname_converter(PyObject *in, void *_out)
14311431
PyErr_SetString(PyExc_OverflowError, "string is too long");
14321432
return 0;
14331433
}
1434-
if (strlen(s) != size) {
1434+
if (strlen(s) != (size_t)size) {
14351435
PyErr_SetString(PyExc_ValueError, "null character in string");
14361436
return 0;
14371437
}

0 commit comments

Comments
 (0)