Skip to content

Commit

Permalink
Fix iterration problem for non decimal string
Browse files Browse the repository at this point in the history
When the string transformation to number failed, all following
transformation failed too.

This happend because status in decNumberFromString function is
updated just in error case. Reusing the DEC_CONTEXT that failed
before results into error even if the string is valid number.
  • Loading branch information
thalman committed Feb 3, 2022
1 parent a9f97e9 commit 13367e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ static jv jvp_literal_number_new(const char * literal) {
n->refcnt = JV_REFCNT_INIT;
n->literal_data = NULL;
decContext *ctx = DEC_CONTEXT();
decContextClearStatus(ctx, DEC_Conversion_syntax);
decNumberFromString(&n->num_decimal, literal, ctx);
n->num_double = NAN;

Expand Down
5 changes: 5 additions & 0 deletions tests/man.test
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,8 @@ true
{"foo": 42}
{"foo": 43}

.[]|tonumber?
["1", "hello", "3", 4]
1
3
4

0 comments on commit 13367e4

Please sign in to comment.