Skip to content

Commit c4d39c4

Browse files
thalmannicowilliams
authored andcommitted
Fix iterration problem for non decimal string
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.
1 parent 174db0f commit c4d39c4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/jv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ static jv jvp_literal_number_new(const char * literal) {
612612
n->refcnt = JV_REFCNT_INIT;
613613
n->literal_data = NULL;
614614
decContext *ctx = DEC_CONTEXT();
615+
decContextClearStatus(ctx, DEC_Conversion_syntax);
615616
decNumberFromString(&n->num_decimal, literal, ctx);
616617
n->num_double = NAN;
617618

tests/man.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,8 @@ true
841841
{"foo": 42}
842842
{"foo": 43}
843843

844+
.[]|tonumber?
845+
["1", "hello", "3", 4]
846+
1
847+
3
848+
4

0 commit comments

Comments
 (0)