Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d23a4e

Browse files
committed
make_pair(): When comparing the pointers, they must be cast to integer
types (i.e. Py_uintptr_t, our spelling of C9X's uintptr_t). ANSI specifies that pointer compares other than == and != to non-related structures are undefined. This quiets an Insure portability warning.
1 parent 67c1a04 commit 9d23a4e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Objects/object.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,14 @@ static PyObject *
371371
make_pair(PyObject *v, PyObject *w)
372372
{
373373
PyObject *pair;
374+
Py_uintptr_t iv = (Py_uintptr_t)v;
375+
Py_uintptr_t iw = (Py_uintptr_t)w;
374376

375377
pair = PyTuple_New(2);
376378
if (pair == NULL) {
377379
return NULL;
378380
}
379-
if (v <= w) {
381+
if (iv <= iw) {
380382
PyTuple_SET_ITEM(pair, 0, PyLong_FromVoidPtr((void *)v));
381383
PyTuple_SET_ITEM(pair, 1, PyLong_FromVoidPtr((void *)w));
382384
} else {
@@ -487,7 +489,9 @@ PyObject_Compare(PyObject *v, PyObject *w)
487489
return strcmp(vname, wname);
488490
}
489491
if (vtp->tp_compare == NULL) {
490-
return (v < w) ? -1 : 1;
492+
Py_uintptr_t iv = (Py_uintptr_t)v;
493+
Py_uintptr_t iw = (Py_uintptr_t)w;
494+
return (iv < iw) ? -1 : 1;
491495
}
492496
_PyCompareState_nesting++;
493497
if (_PyCompareState_nesting > NESTING_LIMIT

0 commit comments

Comments
 (0)