diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-30 13:18:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-30 13:18:19 -0400 |
| commit | 42084fda6f0f45f2b13aa2867bd26acf4ef9eae2 (patch) | |
| tree | 4f24a47b85c4892519dc093dcaae914285e9324c /repl.c | |
| parent | 7048c827c087a9dbe889dd033a13fe4a3e08101f (diff) | |
Fix indexing errors
Diffstat (limited to 'repl.c')
| -rw-r--r-- | repl.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -444,11 +444,12 @@ void eval(env_t *env, ast_t *ast, void *dest) case ArrayType: { array_t arr; eval(env, index->indexed, &arr); - int64_t index_int = ast_to_int(env, index->index); + int64_t raw_index = ast_to_int(env, index->index); + int64_t index_int = raw_index; if (index_int < 1) index_int = arr.length + index_int + 1; if (index_int < 1 || index_int > arr.length) repl_err(index->index, "%ld is an invalid index for an array with length %ld", - index_int, arr.length); + raw_index, arr.length); size_t item_size = type_size(Match(indexed_t, ArrayType)->item_type); memcpy(dest, arr.data + arr.stride*(index_int-1), item_size); break; |
