Issue #22156: Fix some "comparison between signed and unsigned integers"
compiler warnings in the Modules/ subdirectory.
This commit is contained in:
parent
12174a5dca
commit
706768c687
|
@ -188,7 +188,7 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
|
||||||
if (action == BZ_FINISH && bzerror == BZ_STREAM_END)
|
if (action == BZ_FINISH && bzerror == BZ_STREAM_END)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (data_size != PyBytes_GET_SIZE(result))
|
if (data_size != (size_t)PyBytes_GET_SIZE(result))
|
||||||
if (_PyBytes_Resize(&result, data_size) < 0)
|
if (_PyBytes_Resize(&result, data_size) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
return result;
|
return result;
|
||||||
|
@ -457,7 +457,7 @@ decompress(BZ2Decompressor *d, char *data, size_t len)
|
||||||
d->bzs.avail_out = (unsigned int)Py_MIN(buffer_left, UINT_MAX);
|
d->bzs.avail_out = (unsigned int)Py_MIN(buffer_left, UINT_MAX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data_size != PyBytes_GET_SIZE(result))
|
if (data_size != (size_t)PyBytes_GET_SIZE(result))
|
||||||
if (_PyBytes_Resize(&result, data_size) < 0)
|
if (_PyBytes_Resize(&result, data_size) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -290,7 +290,7 @@ dialect_check_quoting(int quoting)
|
||||||
StyleDesc *qs;
|
StyleDesc *qs;
|
||||||
|
|
||||||
for (qs = quote_styles; qs->name; qs++) {
|
for (qs = quote_styles; qs->name; qs++) {
|
||||||
if (qs->style == quoting)
|
if ((int)qs->style == quoting)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
PyErr_Format(PyExc_TypeError, "bad \"quoting\" value");
|
PyErr_Format(PyExc_TypeError, "bad \"quoting\" value");
|
||||||
|
|
|
@ -1606,7 +1606,7 @@ resize(PyObject *self, PyObject *args)
|
||||||
"Memory cannot be resized because this object doesn't own it");
|
"Memory cannot be resized because this object doesn't own it");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (size <= sizeof(obj->b_value)) {
|
if ((size_t)size <= sizeof(obj->b_value)) {
|
||||||
/* internal default buffer is large enough */
|
/* internal default buffer is large enough */
|
||||||
obj->b_size = size;
|
obj->b_size = size;
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
@ -3741,7 +3741,7 @@ PyInit__elementtree(void)
|
||||||
if (expat_capi) {
|
if (expat_capi) {
|
||||||
/* check that it's usable */
|
/* check that it's usable */
|
||||||
if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 ||
|
if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 ||
|
||||||
expat_capi->size < sizeof(struct PyExpat_CAPI) ||
|
(size_t)expat_capi->size < sizeof(struct PyExpat_CAPI) ||
|
||||||
expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION ||
|
expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION ||
|
||||||
expat_capi->MINOR_VERSION != XML_MINOR_VERSION ||
|
expat_capi->MINOR_VERSION != XML_MINOR_VERSION ||
|
||||||
expat_capi->MICRO_VERSION != XML_MICRO_VERSION) {
|
expat_capi->MICRO_VERSION != XML_MICRO_VERSION) {
|
||||||
|
|
|
@ -53,10 +53,12 @@ unshare(bytesio *self, size_t preferred_size, int truncate)
|
||||||
Py_ssize_t copy_size;
|
Py_ssize_t copy_size;
|
||||||
char *new_buf;
|
char *new_buf;
|
||||||
|
|
||||||
if((! truncate) && preferred_size < self->string_size) {
|
if((! truncate) && preferred_size < (size_t)self->string_size) {
|
||||||
preferred_size = self->string_size;
|
preferred_size = self->string_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* PyMem_Malloc() returns NULL if preferred_size is bigger
|
||||||
|
than PY_SSIZE_T_MAX */
|
||||||
new_buf = (char *)PyMem_Malloc(preferred_size);
|
new_buf = (char *)PyMem_Malloc(preferred_size);
|
||||||
if (new_buf == NULL) {
|
if (new_buf == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
|
@ -64,7 +66,7 @@ unshare(bytesio *self, size_t preferred_size, int truncate)
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_size = self->string_size;
|
copy_size = self->string_size;
|
||||||
if (copy_size > preferred_size) {
|
if ((size_t)copy_size > preferred_size) {
|
||||||
copy_size = preferred_size;
|
copy_size = preferred_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1730,7 +1730,7 @@ _PyIO_find_line_ending(
|
||||||
else {
|
else {
|
||||||
/* Non-universal mode. */
|
/* Non-universal mode. */
|
||||||
Py_ssize_t readnl_len = PyUnicode_GET_LENGTH(readnl);
|
Py_ssize_t readnl_len = PyUnicode_GET_LENGTH(readnl);
|
||||||
char *nl = PyUnicode_DATA(readnl);
|
Py_UCS1 *nl = PyUnicode_1BYTE_DATA(readnl);
|
||||||
/* Assume that readnl is an ASCII character. */
|
/* Assume that readnl is an ASCII character. */
|
||||||
assert(PyUnicode_KIND(readnl) == PyUnicode_1BYTE_KIND);
|
assert(PyUnicode_KIND(readnl) == PyUnicode_1BYTE_KIND);
|
||||||
if (readnl_len == 1) {
|
if (readnl_len == 1) {
|
||||||
|
|
|
@ -1236,7 +1236,7 @@ pattern_repr(PatternObject *obj)
|
||||||
};
|
};
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
PyObject *flag_items;
|
PyObject *flag_items;
|
||||||
int i;
|
size_t i;
|
||||||
int flags = obj->flags;
|
int flags = obj->flags;
|
||||||
|
|
||||||
/* Omit re.UNICODE for valid string patterns. */
|
/* Omit re.UNICODE for valid string patterns. */
|
||||||
|
|
|
@ -1263,7 +1263,8 @@ prepare_s(PyStructObject *self)
|
||||||
const char *s;
|
const char *s;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
char c;
|
char c;
|
||||||
Py_ssize_t size, len, ncodes, num, itemsize;
|
Py_ssize_t size, len, num, itemsize;
|
||||||
|
size_t ncodes;
|
||||||
|
|
||||||
fmt = PyBytes_AS_STRING(self->s_format);
|
fmt = PyBytes_AS_STRING(self->s_format);
|
||||||
|
|
||||||
|
@ -1319,7 +1320,7 @@ prepare_s(PyStructObject *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for overflow */
|
/* check for overflow */
|
||||||
if ((ncodes + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) {
|
if ((ncodes + 1) > ((size_t)PY_SSIZE_T_MAX / sizeof(formatcode))) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1719,7 +1719,7 @@ test_long_numbits(PyObject *self)
|
||||||
{-0xffffL, 16, -1},
|
{-0xffffL, 16, -1},
|
||||||
{0xfffffffL, 28, 1},
|
{0xfffffffL, 28, 1},
|
||||||
{-0xfffffffL, 28, -1}};
|
{-0xfffffffL, 28, -1}};
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) {
|
for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) {
|
||||||
size_t nbits;
|
size_t nbits;
|
||||||
|
|
|
@ -1414,7 +1414,7 @@ varname_converter(PyObject *in, void *_out)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s = PyBytes_AsString(in);
|
s = PyBytes_AsString(in);
|
||||||
if (strlen(s) != PyBytes_Size(in)) {
|
if (strlen(s) != (size_t)PyBytes_Size(in)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "null byte in bytes object");
|
PyErr_SetString(PyExc_ValueError, "null byte in bytes object");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1431,7 +1431,7 @@ varname_converter(PyObject *in, void *_out)
|
||||||
PyErr_SetString(PyExc_OverflowError, "string is too long");
|
PyErr_SetString(PyExc_OverflowError, "string is too long");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strlen(s) != size) {
|
if (strlen(s) != (size_t)size) {
|
||||||
PyErr_SetString(PyExc_ValueError, "null character in string");
|
PyErr_SetString(PyExc_ValueError, "null character in string");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ typedef struct {
|
||||||
(sizeof(traceback_t) + sizeof(frame_t) * (NFRAME - 1))
|
(sizeof(traceback_t) + sizeof(frame_t) * (NFRAME - 1))
|
||||||
|
|
||||||
#define MAX_NFRAME \
|
#define MAX_NFRAME \
|
||||||
((INT_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1)
|
(((size_t)INT_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1)
|
||||||
|
|
||||||
static PyObject *unknown_filename = NULL;
|
static PyObject *unknown_filename = NULL;
|
||||||
static traceback_t tracemalloc_empty_traceback;
|
static traceback_t tracemalloc_empty_traceback;
|
||||||
|
@ -874,7 +874,7 @@ tracemalloc_start(int max_nframe)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(1 <= max_nframe && max_nframe <= MAX_NFRAME);
|
assert(1 <= max_nframe && (size_t)max_nframe <= MAX_NFRAME);
|
||||||
tracemalloc_config.max_nframe = max_nframe;
|
tracemalloc_config.max_nframe = max_nframe;
|
||||||
|
|
||||||
/* allocate a buffer to store a new traceback */
|
/* allocate a buffer to store a new traceback */
|
||||||
|
@ -1226,7 +1226,7 @@ py_tracemalloc_start(PyObject *self, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "|n:start", &nframe))
|
if (!PyArg_ParseTuple(args, "|n:start", &nframe))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (nframe < 1 || nframe > MAX_NFRAME) {
|
if (nframe < 1 || (size_t)nframe > MAX_NFRAME) {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"the number of frames must be in range [1; %i]",
|
"the number of frames must be in range [1; %i]",
|
||||||
(int)MAX_NFRAME);
|
(int)MAX_NFRAME);
|
||||||
|
@ -1388,7 +1388,7 @@ parse_sys_xoptions(PyObject *value)
|
||||||
if (nframe == -1 && PyErr_Occurred())
|
if (nframe == -1 && PyErr_Occurred())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (nframe < 1 || nframe > MAX_NFRAME)
|
if (nframe < 1 || (size_t)nframe > MAX_NFRAME)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return Py_SAFE_DOWNCAST(nframe, long, int);
|
return Py_SAFE_DOWNCAST(nframe, long, int);
|
||||||
|
@ -1412,7 +1412,7 @@ _PyTraceMalloc_Init(void)
|
||||||
value = strtol(p, &endptr, 10);
|
value = strtol(p, &endptr, 10);
|
||||||
if (*endptr != '\0'
|
if (*endptr != '\0'
|
||||||
|| value < 1
|
|| value < 1
|
||||||
|| value > MAX_NFRAME
|
|| (size_t)value > MAX_NFRAME
|
||||||
|| errno == ERANGE)
|
|| errno == ERANGE)
|
||||||
{
|
{
|
||||||
Py_FatalError("PYTHONTRACEMALLOC: invalid number of frames");
|
Py_FatalError("PYTHONTRACEMALLOC: invalid number of frames");
|
||||||
|
|
|
@ -2000,7 +2000,7 @@ array_reconstructor(PyObject *self, PyObject *args)
|
||||||
*/
|
*/
|
||||||
for (descr = descriptors; descr->typecode != '\0'; descr++) {
|
for (descr = descriptors; descr->typecode != '\0'; descr++) {
|
||||||
if (descr->is_integer_type &&
|
if (descr->is_integer_type &&
|
||||||
descr->itemsize == mf_descr.size &&
|
(size_t)descr->itemsize == mf_descr.size &&
|
||||||
descr->is_signed == mf_descr.is_signed)
|
descr->is_signed == mf_descr.is_signed)
|
||||||
typecode = descr->typecode;
|
typecode = descr->typecode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -902,7 +902,7 @@ path_converter(PyObject *o, void *p) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
narrow = PyBytes_AS_STRING(bytes);
|
narrow = PyBytes_AS_STRING(bytes);
|
||||||
if (length != strlen(narrow)) {
|
if ((size_t)length != strlen(narrow)) {
|
||||||
FORMAT_EXCEPTION(PyExc_ValueError, "embedded NUL character in %s");
|
FORMAT_EXCEPTION(PyExc_ValueError, "embedded NUL character in %s");
|
||||||
Py_DECREF(bytes);
|
Py_DECREF(bytes);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue