mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
Issue #22156: Fix "comparison between signed and unsigned integers" compiler
warnings in the Objects/ subdirectory. PyType_FromSpecWithBases() and PyType_FromSpec() now reject explicitly negative slot identifiers.
This commit is contained in:
parent
98ea54c35c
commit
12174a5dca
5 changed files with 13 additions and 12 deletions
|
@ -2714,7 +2714,7 @@ _PyErr_TrySetFromCause(const char *format, ...)
|
||||||
same_basic_size = (
|
same_basic_size = (
|
||||||
caught_type_size == base_exc_size ||
|
caught_type_size == base_exc_size ||
|
||||||
(PyType_SUPPORTS_WEAKREFS(caught_type) &&
|
(PyType_SUPPORTS_WEAKREFS(caught_type) &&
|
||||||
(caught_type_size == base_exc_size + sizeof(PyObject *))
|
(caught_type_size == base_exc_size + (Py_ssize_t)sizeof(PyObject *))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (caught_type->tp_init != (initproc)BaseException_init ||
|
if (caught_type->tp_init != (initproc)BaseException_init ||
|
||||||
|
|
|
@ -5094,13 +5094,13 @@ _PyLong_Init(void)
|
||||||
* to the original refcnt + 1 */
|
* to the original refcnt + 1 */
|
||||||
Py_REFCNT(op) = refcnt + 1;
|
Py_REFCNT(op) = refcnt + 1;
|
||||||
assert(Py_SIZE(op) == size);
|
assert(Py_SIZE(op) == size);
|
||||||
assert(v->ob_digit[0] == abs(ival));
|
assert(v->ob_digit[0] == (digit)abs(ival));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(void)PyObject_INIT(v, &PyLong_Type);
|
(void)PyObject_INIT(v, &PyLong_Type);
|
||||||
}
|
}
|
||||||
Py_SIZE(v) = size;
|
Py_SIZE(v) = size;
|
||||||
v->ob_digit[0] = abs(ival);
|
v->ob_digit[0] = (digit)abs(ival);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* initialize int_info */
|
/* initialize int_info */
|
||||||
|
|
|
@ -771,7 +771,7 @@ frozenset_hash(PyObject *self)
|
||||||
/* Make the final result spread-out in a different pattern
|
/* Make the final result spread-out in a different pattern
|
||||||
than the algorithm for tuples or other python objects. */
|
than the algorithm for tuples or other python objects. */
|
||||||
hash = hash * 69069U + 907133923UL;
|
hash = hash * 69069U + 907133923UL;
|
||||||
if (hash == -1)
|
if (hash == (Py_uhash_t)-1)
|
||||||
hash = 590923713UL;
|
hash = 590923713UL;
|
||||||
so->hash = hash;
|
so->hash = hash;
|
||||||
return hash;
|
return hash;
|
||||||
|
|
|
@ -2622,7 +2622,8 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
|
||||||
type->tp_itemsize = spec->itemsize;
|
type->tp_itemsize = spec->itemsize;
|
||||||
|
|
||||||
for (slot = spec->slots; slot->slot; slot++) {
|
for (slot = spec->slots; slot->slot; slot++) {
|
||||||
if (slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) {
|
if (slot->slot < 0
|
||||||
|
|| (size_t)slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
|
PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -2682,11 +2683,11 @@ PyType_FromSpec(PyType_Spec *spec)
|
||||||
void *
|
void *
|
||||||
PyType_GetSlot(PyTypeObject *type, int slot)
|
PyType_GetSlot(PyTypeObject *type, int slot)
|
||||||
{
|
{
|
||||||
if (!PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
|
if (!PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE) || slot < 0) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (slot >= Py_ARRAY_LENGTH(slotoffsets)) {
|
if ((size_t)slot >= Py_ARRAY_LENGTH(slotoffsets)) {
|
||||||
/* Extension module requesting slot from a future version */
|
/* Extension module requesting slot from a future version */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3519,7 +3519,7 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
|
||||||
if (locale_error_handler(errors, &surrogateescape) < 0)
|
if (locale_error_handler(errors, &surrogateescape) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (str[len] != '\0' || len != strlen(str)) {
|
if (str[len] != '\0' || (size_t)len != strlen(str)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "embedded null character");
|
PyErr_SetString(PyExc_TypeError, "embedded null character");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3696,7 +3696,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)
|
||||||
}
|
}
|
||||||
size = PyBytes_GET_SIZE(output);
|
size = PyBytes_GET_SIZE(output);
|
||||||
data = PyBytes_AS_STRING(output);
|
data = PyBytes_AS_STRING(output);
|
||||||
if (size != strlen(data)) {
|
if ((size_t)size != strlen(data)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "embedded NUL character");
|
PyErr_SetString(PyExc_TypeError, "embedded NUL character");
|
||||||
Py_DECREF(output);
|
Py_DECREF(output);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8874,7 +8874,7 @@ PyUnicode_TransformDecimalToASCII(Py_UNICODE *s,
|
||||||
|
|
||||||
maxchar = 127;
|
maxchar = 127;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
Py_UNICODE ch = s[i];
|
Py_UCS4 ch = s[i];
|
||||||
if (ch > 127) {
|
if (ch > 127) {
|
||||||
int decimal = Py_UNICODE_TODECIMAL(ch);
|
int decimal = Py_UNICODE_TODECIMAL(ch);
|
||||||
if (decimal >= 0)
|
if (decimal >= 0)
|
||||||
|
@ -8891,7 +8891,7 @@ PyUnicode_TransformDecimalToASCII(Py_UNICODE *s,
|
||||||
data = PyUnicode_DATA(decimal);
|
data = PyUnicode_DATA(decimal);
|
||||||
/* Iterate over code points */
|
/* Iterate over code points */
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
Py_UNICODE ch = s[i];
|
Py_UCS4 ch = s[i];
|
||||||
if (ch > 127) {
|
if (ch > 127) {
|
||||||
int decimal = Py_UNICODE_TODECIMAL(ch);
|
int decimal = Py_UNICODE_TODECIMAL(ch);
|
||||||
if (decimal >= 0)
|
if (decimal >= 0)
|
||||||
|
@ -10833,7 +10833,7 @@ PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str)
|
||||||
void *data = PyUnicode_DATA(uni);
|
void *data = PyUnicode_DATA(uni);
|
||||||
/* Compare Unicode string and source character set string */
|
/* Compare Unicode string and source character set string */
|
||||||
for (i = 0; (chr = PyUnicode_READ(kind, data, i)) && str[i]; i++)
|
for (i = 0; (chr = PyUnicode_READ(kind, data, i)) && str[i]; i++)
|
||||||
if (chr != str[i])
|
if (chr != (unsigned char)str[i])
|
||||||
return (chr < (unsigned char)(str[i])) ? -1 : 1;
|
return (chr < (unsigned char)(str[i])) ? -1 : 1;
|
||||||
/* This check keeps Python strings that end in '\0' from comparing equal
|
/* This check keeps Python strings that end in '\0' from comparing equal
|
||||||
to C strings identical up to that point. */
|
to C strings identical up to that point. */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue