Skip to content

Commit

Permalink
Berry assigment to list with negative index (arendst#20537)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored and hawa-lc4 committed Jan 20, 2024
1 parent c7181ea commit 4b0e29e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions lib/libesp32/berry/src/be_api.c
Expand Up @@ -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)
Expand Down

0 comments on commit 4b0e29e

Please sign in to comment.