py/vm: Prevent array bound warning when using -MP_OBJ_ITER_BUF_NSLOTS.
This warning can happen on clang 13.0.1 building mpy-cross: ../py/vm.c:748:25: error: array index -3 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements) [-Werror,-Warray-bounds] sp[-MP_OBJ_ITER_BUF_NSLOTS + 1] = MP_OBJ_NULL; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Using pointer access instead of array access works around this warning. Fixes issue #8467. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
7e8222ae06
commit
bb70874111
8
py/vm.c
8
py/vm.c
|
@ -745,8 +745,8 @@ unwind_jump:;
|
|||
obj = mp_getiter(obj, iter_buf);
|
||||
if (obj != MP_OBJ_FROM_PTR(iter_buf)) {
|
||||
// Iterator didn't use the stack so indicate that with MP_OBJ_NULL.
|
||||
sp[-MP_OBJ_ITER_BUF_NSLOTS + 1] = MP_OBJ_NULL;
|
||||
sp[-MP_OBJ_ITER_BUF_NSLOTS + 2] = obj;
|
||||
*(sp - MP_OBJ_ITER_BUF_NSLOTS + 1) = MP_OBJ_NULL;
|
||||
*(sp - MP_OBJ_ITER_BUF_NSLOTS + 2) = obj;
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
@ -757,8 +757,8 @@ unwind_jump:;
|
|||
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
|
||||
code_state->sp = sp;
|
||||
mp_obj_t obj;
|
||||
if (sp[-MP_OBJ_ITER_BUF_NSLOTS + 1] == MP_OBJ_NULL) {
|
||||
obj = sp[-MP_OBJ_ITER_BUF_NSLOTS + 2];
|
||||
if (*(sp - MP_OBJ_ITER_BUF_NSLOTS + 1) == MP_OBJ_NULL) {
|
||||
obj = *(sp - MP_OBJ_ITER_BUF_NSLOTS + 2);
|
||||
} else {
|
||||
obj = MP_OBJ_FROM_PTR(&sp[-MP_OBJ_ITER_BUF_NSLOTS + 1]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue