Skip to content

Commit

Permalink
py/vm: Prevent array bound warning when using -MP_OBJ_ITER_BUF_NSLOTS.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dpgeorge committed Mar 30, 2022
1 parent 7e8222a commit bb70874
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions py/vm.c
Expand Up @@ -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();
}
Expand All @@ -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]);
}
Expand Down

0 comments on commit bb70874

Please sign in to comment.