diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-08-15 23:03:39 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-08-15 23:03:39 (GMT) |
commit | 706768c687f5413c909168736506aaf4fb4861c0 (patch) | |
tree | 98131f201f269d30031ed6e3c6d98fe4cf1fe649 /Modules | |
parent | 12174a5dcaf1bdcd8d5fd790a8cad07049bddce6 (diff) | |
download | cpython-706768c687f5413c909168736506aaf4fb4861c0.zip cpython-706768c687f5413c909168736506aaf4fb4861c0.tar.gz cpython-706768c687f5413c909168736506aaf4fb4861c0.tar.bz2 |
Issue #22156: Fix some "comparison between signed and unsigned integers"
compiler warnings in the Modules/ subdirectory.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_bz2module.c | 4 | ||||
-rw-r--r-- | Modules/_csv.c | 2 | ||||
-rw-r--r-- | Modules/_ctypes/callproc.c | 2 | ||||
-rw-r--r-- | Modules/_elementtree.c | 2 | ||||
-rw-r--r-- | Modules/_io/bytesio.c | 6 | ||||
-rw-r--r-- | Modules/_io/textio.c | 2 | ||||
-rw-r--r-- | Modules/_sre.c | 2 | ||||
-rw-r--r-- | Modules/_struct.c | 5 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 2 | ||||
-rw-r--r-- | Modules/_tkinter.c | 4 | ||||
-rw-r--r-- | Modules/_tracemalloc.c | 10 | ||||
-rw-r--r-- | Modules/arraymodule.c | 2 | ||||
-rw-r--r-- | Modules/posixmodule.c | 2 |
13 files changed, 24 insertions, 21 deletions
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index e652f4d..4f2afda 100644 --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -188,7 +188,7 @@ compress(BZ2Compressor *c, char *data, size_t len, int action) if (action == BZ_FINISH && bzerror == BZ_STREAM_END) break; } - if (data_size != PyBytes_GET_SIZE(result)) + if (data_size != (size_t)PyBytes_GET_SIZE(result)) if (_PyBytes_Resize(&result, data_size) < 0) goto error; 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); } } - if (data_size != PyBytes_GET_SIZE(result)) + if (data_size != (size_t)PyBytes_GET_SIZE(result)) if (_PyBytes_Resize(&result, data_size) < 0) goto error; return result; diff --git a/Modules/_csv.c b/Modules/_csv.c index 6eaaea2..ade35e5 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -290,7 +290,7 @@ dialect_check_quoting(int quoting) StyleDesc *qs; for (qs = quote_styles; qs->name; qs++) { - if (qs->style == quoting) + if ((int)qs->style == quoting) return 0; } PyErr_Format(PyExc_TypeError, "bad \"quoting\" value"); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 74119a3..d365e38 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1606,7 +1606,7 @@ resize(PyObject *self, PyObject *args) "Memory cannot be resized because this object doesn't own it"); return NULL; } - if (size <= sizeof(obj->b_value)) { + if ((size_t)size <= sizeof(obj->b_value)) { /* internal default buffer is large enough */ obj->b_size = size; goto done; diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index b3b6976..9b3e9ed 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3741,7 +3741,7 @@ PyInit__elementtree(void) if (expat_capi) { /* check that it's usable */ 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->MINOR_VERSION != XML_MINOR_VERSION || expat_capi->MICRO_VERSION != XML_MICRO_VERSION) { diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index d07da08..56ad788 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -53,10 +53,12 @@ unshare(bytesio *self, size_t preferred_size, int truncate) Py_ssize_t copy_size; char *new_buf; - if((! truncate) && preferred_size < self->string_size) { + if((! truncate) && preferred_size < (size_t)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); if (new_buf == NULL) { PyErr_NoMemory(); @@ -64,7 +66,7 @@ unshare(bytesio *self, size_t preferred_size, int truncate) } copy_size = self->string_size; - if (copy_size > preferred_size) { + if ((size_t)copy_size > preferred_size) { copy_size = preferred_size; } diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index aed5b2d..b4c3c40 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1730,7 +1730,7 @@ _PyIO_find_line_ending( else { /* Non-universal mode. */ 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. */ assert(PyUnicode_KIND(readnl) == PyUnicode_1BYTE_KIND); if (readnl_len == 1) { diff --git a/Modules/_sre.c b/Modules/_sre.c index 300d883..13479ba 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1236,7 +1236,7 @@ pattern_repr(PatternObject *obj) }; PyObject *result = NULL; PyObject *flag_items; - int i; + size_t i; int flags = obj->flags; /* Omit re.UNICODE for valid string patterns. */ diff --git a/Modules/_struct.c b/Modules/_struct.c index 4941fc8..06f0d3a 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1263,7 +1263,8 @@ prepare_s(PyStructObject *self) const char *s; const char *fmt; 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); @@ -1319,7 +1320,7 @@ prepare_s(PyStructObject *self) } /* 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(); return -1; } diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 9f20abb..643cbde 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1719,7 +1719,7 @@ test_long_numbits(PyObject *self) {-0xffffL, 16, -1}, {0xfffffffL, 28, 1}, {-0xfffffffL, 28, -1}}; - int i; + size_t i; for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) { size_t nbits; diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index b5f23bc..0717594 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -1414,7 +1414,7 @@ varname_converter(PyObject *in, void *_out) return 0; } 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"); return 0; } @@ -1431,7 +1431,7 @@ varname_converter(PyObject *in, void *_out) PyErr_SetString(PyExc_OverflowError, "string is too long"); return 0; } - if (strlen(s) != size) { + if (strlen(s) != (size_t)size) { PyErr_SetString(PyExc_ValueError, "null character in string"); return 0; } diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 257ae1b..e0024e9 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -79,7 +79,7 @@ typedef struct { (sizeof(traceback_t) + sizeof(frame_t) * (NFRAME - 1)) #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 traceback_t tracemalloc_empty_traceback; @@ -874,7 +874,7 @@ tracemalloc_start(int max_nframe) 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; /* 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)) return NULL; - if (nframe < 1 || nframe > MAX_NFRAME) { + if (nframe < 1 || (size_t)nframe > MAX_NFRAME) { PyErr_Format(PyExc_ValueError, "the number of frames must be in range [1; %i]", (int)MAX_NFRAME); @@ -1388,7 +1388,7 @@ parse_sys_xoptions(PyObject *value) if (nframe == -1 && PyErr_Occurred()) return -1; - if (nframe < 1 || nframe > MAX_NFRAME) + if (nframe < 1 || (size_t)nframe > MAX_NFRAME) return -1; return Py_SAFE_DOWNCAST(nframe, long, int); @@ -1412,7 +1412,7 @@ _PyTraceMalloc_Init(void) value = strtol(p, &endptr, 10); if (*endptr != '\0' || value < 1 - || value > MAX_NFRAME + || (size_t)value > MAX_NFRAME || errno == ERANGE) { Py_FatalError("PYTHONTRACEMALLOC: invalid number of frames"); diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 4a1c158..d0c94f7 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -2000,7 +2000,7 @@ array_reconstructor(PyObject *self, PyObject *args) */ for (descr = descriptors; descr->typecode != '\0'; descr++) { if (descr->is_integer_type && - descr->itemsize == mf_descr.size && + (size_t)descr->itemsize == mf_descr.size && descr->is_signed == mf_descr.is_signed) typecode = descr->typecode; } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 533d7b4..af5c2a6 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -902,7 +902,7 @@ path_converter(PyObject *o, void *p) { #endif narrow = PyBytes_AS_STRING(bytes); - if (length != strlen(narrow)) { + if ((size_t)length != strlen(narrow)) { FORMAT_EXCEPTION(PyExc_ValueError, "embedded NUL character in %s"); Py_DECREF(bytes); return 0; |