Skip to content

Commit cd17662

Browse files
committed
Fix "warning: comparison between signed and unsigned integer expressions"
-Wsign-compare warnings in unicodeobject.c. These were all a result of sizeof() being unsigned and being compared to a Py_ssize_t. Not actual problems.
1 parent b4b9841 commit cd17662

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Objects/unicodeobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
816816
assert(_PyUnicode_WSTR(unicode) != NULL);
817817

818818
/* check for integer overflow */
819-
if (length > PY_SSIZE_T_MAX / sizeof(wchar_t) - 1) {
819+
if (length > PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) - 1) {
820820
PyErr_NoMemory();
821821
return -1;
822822
}
@@ -888,7 +888,7 @@ _PyUnicode_New(Py_ssize_t length)
888888
}
889889

890890
/* Ensure we won't overflow the size. */
891-
if (length > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) {
891+
if (length > ((PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UNICODE)) - 1)) {
892892
return (PyUnicodeObject *)PyErr_NoMemory();
893893
}
894894
if (length < 0) {
@@ -2239,7 +2239,7 @@ as_ucs4(PyObject *string, Py_UCS4 *target, Py_ssize_t targetsize,
22392239
if (copy_null)
22402240
targetlen++;
22412241
if (!target) {
2242-
if (PY_SSIZE_T_MAX / sizeof(Py_UCS4) < targetlen) {
2242+
if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UCS4) < targetlen) {
22432243
PyErr_NoMemory();
22442244
return NULL;
22452245
}
@@ -2852,7 +2852,7 @@ PyUnicode_AsWideCharString(PyObject *unicode,
28522852
buflen = unicode_aswidechar(unicode, NULL, 0);
28532853
if (buflen == -1)
28542854
return NULL;
2855-
if (PY_SSIZE_T_MAX / sizeof(wchar_t) < buflen) {
2855+
if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) < buflen) {
28562856
PyErr_NoMemory();
28572857
return NULL;
28582858
}
@@ -15430,7 +15430,7 @@ PyUnicode_AsUnicodeCopy(PyObject *unicode)
1543015430
if (u == NULL)
1543115431
return NULL;
1543215432
/* Ensure we won't overflow the size. */
15433-
if (len > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) {
15433+
if (len > ((PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UNICODE)) - 1)) {
1543415434
PyErr_NoMemory();
1543515435
return NULL;
1543615436
}

0 commit comments

Comments
 (0)