From 06c2d78d5f370f181893eb176c8fdf67158384a9 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Thu, 18 Jan 2024 22:01:39 +0100 Subject: [PATCH] Berry assigment to list with negative index (#20537) --- CHANGELOG.md | 1 + lib/libesp32/berry/src/be_api.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ec363e55..138793c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file. - Web file upload response on upload error (#20340) - ESP32 shutter exception 6 (divide by zero) on ``ShutterMode 4`` (#20524) - GPIOViewer exception 3 +- Berry assigment to list with negative index ### Removed - Max number of 30 backlog entries diff --git a/lib/libesp32/berry/src/be_api.c b/lib/libesp32/berry/src/be_api.c index 5cc755929..31755604f 100644 --- a/lib/libesp32/berry/src/be_api.c +++ b/lib/libesp32/berry/src/be_api.c @@ -731,10 +731,13 @@ BERRY_API bbool be_getindex(bvm *vm, int index) static bvalue* list_setindex(blist *list, bvalue *key) { int idx = var_toidx(key); - if (idx < be_list_count(list)) { - return be_list_at(list, idx); + if (idx < 0) { + idx = list->count + idx; } - return NULL; + if (idx < 0 || idx >= list->count) { + return NULL; + } + return be_list_at(list, idx); } BERRY_API bbool be_setindex(bvm *vm, int index)