Skip to content

Fix iterration problem for non decimal string #2400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
thalman committed Feb 3, 2022
commit 13367e474840d794b791bca642c7e4fa7856bfcc
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