aboutsummaryrefslogtreecommitdiff
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-03-31 10:57:34 +1100
committerDamien George <damien@micropython.org>2022-03-31 10:59:55 +1100
commitbb70874111dbb246624a68c013e8f1c3245ca0d8 (patch)
tree5189185d865dcce299aeb39de88b5285432175c4 /py/vm.c
parent7e8222ae063d78ae8f901bb0f9fef663edd2edb6 (diff)
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>
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/py/vm.c b/py/vm.c
index 50da90e7d..fa163423a 100644
--- a/py/vm.c
+++ b/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]);
}