10000 Fix compiler warnings and check slot offset can be stored in index field · python/cpython@b07f219 · GitHub
[go: up one dir, main page]

Skip to content

Commit b07f219

Browse files
committed
Fix compiler warnings and check slot offset can be stored in index field
1 parent a0ed9e2 commit b07f219

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Python/specialize.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ specialize_module_load_attr(
257257
return -1;
258258
}
259259
cache1->dk_version_or_hint = keys_version;
260-
cache0->index = index;
260+
cache0->index = (uint16_t)index;
261261
*instr = _Py_MAKECODEUNIT(LOAD_ATTR_MODULE, _Py_OPARG(*instr));
262262
return 0;
263263
}
@@ -298,8 +298,11 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, Sp
298298
goto fail;
299299
}
300300
Py_ssize_t offset = dmem->offset;
301+
if (offset != (uint16_t)offset) {
302+
goto fail;
303+
}
301304
assert(offset > 0);
302-
cache0->index = offset;
305+
cache0->index = (uint16_t)offset;
303306
cache1->tp_version = type->tp_version_tag;
304307
*instr = _Py_MAKECODEUNIT(LOAD_ATTR_SLOT, _Py_OPARG(*instr));
305308
goto success;
@@ -336,7 +339,7 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, Sp
336339
}
337340
cache1->dk_version_or_hint = keys_version;
338341
cache1->tp_version = type->tp_version_tag;
339-
cache0->index = index;
342+
cache0->index = (uint16_t)index;
340343
*instr = _Py_MAKECODEUNIT(LOAD_ATTR_SPLIT_KEYS, _Py_OPARG(*instr));
341344
goto success;
342345
}

0 commit comments

Comments
 (0)
0