Skip to content

Commit

Permalink
Actually use number correctly casted from double to int as index
Browse files Browse the repository at this point in the history
The code was using (int)jv_number_value(k) instead of didx.

follow-up from 0e067ef

Useless assignments to didx detected by clang-tidy.
  • Loading branch information
emanuele6 committed Sep 28, 2023
1 parent 8206bc8 commit fa12ca3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/jv_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ jv jv_get(jv t, jv k) {
} else {
if (didx < INT_MIN) didx = INT_MIN;
if (didx > INT_MAX) didx = INT_MAX;
int idx = (int)jv_number_value(k);
if (idx < 0)
idx += jv_array_length(jv_copy(t));
v = jv_array_get(t, idx);
if (didx < 0)
didx += jv_array_length(jv_copy(t));
v = jv_array_get(t, didx);
if (!jv_is_valid(v)) {
jv_free(v);
v = jv_null();
Expand Down

0 comments on commit fa12ca3

Please sign in to comment.