diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-11-03 11:36:24 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-11-03 11:36:24 +0100 |
| commit | 73648bb2d85962461119df7c215a879f90a71c63 (patch) | |
| tree | 4cc32802bc8f22e3bc4fb5d72a91873c3285b925 /src | |
| parent | ba0daaa70619a2a7976107ddb7c98e3b906c4b2c (diff) | |
Fix #1268.
Error message for enumerated arrays going out of bounds was not yet updated for the Enum change.
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_expr.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index d8ca190b7..1e8c24fd6 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -3660,8 +3660,11 @@ bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast String lo_str = {}; String hi_str = {}; if (bt->Enum.fields.count > 0) { - lo_str = bt->Enum.fields[bt->Enum.min_value_index]->token.string; - hi_str = bt->Enum.fields[bt->Enum.max_value_index]->token.string; + isize lo_idx = gb_clamp(bt->Enum.min_value_index, 0, bt->Enum.fields.count - 1); + isize hi_idx = gb_clamp(bt->Enum.max_value_index, 0, bt->Enum.fields.count - 1); + + lo_str = bt->Enum.fields[lo_idx]->token.string; + hi_str = bt->Enum.fields[hi_idx]->token.string; } bool out_of_bounds = false; |