fixed an array access problem by an out-of-range index in eval_indexed()

This commit is contained in:
hyung-hwan 2020-04-24 16:01:23 +00:00
parent f860798821
commit 1b7ef41ee4

View File

@ -6918,7 +6918,8 @@ static hawk_val_t* eval_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var)
if (idx <= -1) return HAWK_NULL;
arr = ((hawk_val_arr_t*)v)->arr;
return HAWK_ARR_SLOT(arr, idx)? ((hawk_val_t*)HAWK_ARR_DPTR(arr, idx)): ((hawk_val_t*)&hawk_val_nil);
/* return nil if the index is out of range or the element at the index is not set */
return (idx < HAWK_ARR_SIZE(arr) && HAWK_ARR_SLOT(arr, idx))? ((hawk_val_t*)HAWK_ARR_DPTR(arr, idx)): hawk_val_nil;
}
default: