diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-08-17 20:20:00 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-08-17 20:20:00 (GMT) |
commit | 049e509a9f87d1f82ae0ebfe21c226f37ce9fbdb (patch) | |
tree | 96885f696a33000548163e8b4bab6415dd842dde /Objects | |
parent | daca3d7e9b48badf02521df1b729ddd2733b2d77 (diff) | |
download | cpython-049e509a9f87d1f82ae0ebfe21c226f37ce9fbdb.zip cpython-049e509a9f87d1f82ae0ebfe21c226f37ce9fbdb.tar.gz cpython-049e509a9f87d1f82ae0ebfe21c226f37ce9fbdb.tar.bz2 |
Issue #22207: Fix "comparison between signed and unsigned integers" warning in
test checking for integer overflow on Py_ssize_t type: cast explicitly to
size_t.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytesobject.c | 7 | ||||
-rw-r--r-- | Objects/tupleobject.c | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index c5af253..f0c26c3 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -81,6 +81,7 @@ _PyBytes_FromSize(Py_ssize_t size, int use_calloc) { PyBytesObject *op; assert(size >= 0); + if (size == 0 && (op = nullstring) != NULL) { #ifdef COUNT_ALLOCS null_strings++; @@ -89,7 +90,7 @@ _PyBytes_FromSize(Py_ssize_t size, int use_calloc) return (PyObject *)op; } - if (size > PY_SSIZE_T_MAX - PyBytesObject_SIZE) { + if ((size_t)size > (size_t)PY_SSIZE_T_MAX - PyBytesObject_SIZE) { PyErr_SetString(PyExc_OverflowError, "byte string is too large"); return NULL; @@ -1755,7 +1756,7 @@ bytes_count(PyBytesObject *self, PyObject *args) bytes.translate self: self(type="PyBytesObject *") - table: object + table: object Translation table, which must be a bytes object of length 256. [ deletechars: object @@ -3328,7 +3329,7 @@ PyBytes_Concat(PyObject **pv, PyObject *w) /* Only one reference, so we can resize in place */ Py_ssize_t oldsize; Py_buffer wb; - + wb.len = -1; if (_getbuffer(w, &wb) < 0) { PyErr_Format(PyExc_TypeError, "can't concat %.100s to %.100s", diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 753097b..e45462b 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -97,7 +97,7 @@ PyTuple_New(Py_ssize_t size) #endif { /* Check for overflow */ - if (size > (PY_SSIZE_T_MAX - sizeof(PyTupleObject) - + if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - sizeof(PyTupleObject) - sizeof(PyObject *)) / sizeof(PyObject *)) { return PyErr_NoMemory(); } |