Skip to content

Commit

Permalink
Merge pull request #81 from azymohliad/master
Browse files Browse the repository at this point in the history
Avoid mutating nanocbor_get_bool() output on error
  • Loading branch information
bergzand authored Oct 13, 2023
2 parents 15e6b47 + f487768 commit c3bb958
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,18 @@ int nanocbor_get_null(nanocbor_value_t *cvalue)

int nanocbor_get_bool(nanocbor_value_t *cvalue, bool *value)
{
*value = false;
int res = _value_match_exact(cvalue,
NANOCBOR_MASK_FLOAT | NANOCBOR_SIMPLE_FALSE);
if (res < 0) {
*value = true;
if (res >= NANOCBOR_OK) {
*value = false;
} else {
res = _value_match_exact(cvalue,
NANOCBOR_MASK_FLOAT | NANOCBOR_SIMPLE_TRUE);
if (res >= NANOCBOR_OK) {
*value = true;
}
}

return res;
}

Expand Down

0 comments on commit c3bb958

Please sign in to comment.