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

Skip to content

Commit dc55d71

Browse files
committed
PyInstance_DoBinOp(): 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 bc7c7f9 commit dc55d71

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Objects/classobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,13 +1207,16 @@ PyInstance_DoBinOp(PyObject *v, PyObject *w, char *opname, char *ropname,
12071207
{
12081208
char buf[256];
12091209
PyObject *result = NULL;
1210+
12101211
if (halfbinop(v, w, opname, &result, thisfunc, 0) <= 0)
12111212
return result;
12121213
if (halfbinop(w, v, ropname, &result, thisfunc, 1) <= 0)
12131214
return result;
12141215
/* Sigh -- special case for comparisons */
12151216
if (strcmp(opname, "__cmp__") == 0) {
1216-
long c = (v < w) ? -1 : (v > w) ? 1 : 0;
1217+
Py_uintptr_t iv = (Py_uintptr_t)v;
1218+
Py_uintptr_t iw = (Py_uintptr_t)w;
1219+
long c = (iv < iw) ? -1 : (iv > iw) ? 1 : 0;
12171220
return PyInt_FromLong(c);
12181221
}
12191222
sprintf(buf, "%s nor %s defined for these operands", opname, ropname);

0 commit comments

Comments
 (0)