Skip to content

Commit

Permalink
Fixed some errors found by the static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Melchizedek6809 committed Apr 25, 2024
1 parent 24873bb commit 8f24823
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ static bool lMapSetSimple(lMap *map, lVal key, lVal val){
const u32 size = map->size;
const u32 mask = size-1;
u32 off = lHashVal(key) & mask;
if(unlikely(map->entries == NULL)){
return false;
}
for(u32 i=0; i < size; i++){
if(map->entries[off].key.type == ltNil){
map->entries[off].key = key;
Expand Down Expand Up @@ -104,11 +107,13 @@ static void lMapResize(lMap *map, u32 size){
const u32 oldSize = map->size;
map->entries = calloc(size, sizeof(lMapEntry));
map->size = size;
for(uint i=0; i < oldSize; i++){
if(oldEntries[i].key.type == ltNil){ continue;}
lMapSetSimple(map, oldEntries[i].key, oldEntries[i].val);
if(oldEntries != NULL){
for(uint i=0; i < oldSize; i++){
if(oldEntries[i].key.type == ltNil){ continue;}
lMapSetSimple(map, oldEntries[i].key, oldEntries[i].val);
}
free((void *)oldEntries);
}
free((void *)oldEntries);
}

lVal lnfMapNew(lVal v) {
Expand Down

0 comments on commit 8f24823

Please sign in to comment.