fast_jsonparser icon indicating copy to clipboard operation
fast_jsonparser copied to clipboard

Parser is converting some numeric values incorrectly

Open justjoehere opened this issue 4 years ago • 4 comments

Executing the following code FastJsonparser.parse("[{ \"duration\": 7386425359 }]")

Results in { :duration => -1203509233 }

This parsing is resulting in a change in values 7386425359 is being converted to -1203509233

It's like there's a weird conversion from an unsigned to a signed 33 bit conversion taking place. I used this tool to make that guess https://onlinetoolz.net/unsigned-signed#base=10&value=7386425359&bits=33

justjoehere avatar Aug 10 '20 15:08 justjoehere

Hi @justjoehere

Can you confirm this issue on 0.5.0 version ?

anilmaurya avatar Aug 25 '20 17:08 anilmaurya

Still occurs in 0.5.0.

justjoehere avatar Sep 04 '20 17:09 justjoehere

Hi @justjoehere

I added test case to reproduce this issue, https://github.com/anilmaurya/fast_jsonparser/commit/96ff5c513bb8d11ee9d2e593cfb2624a8ff9b9d6

But test cases is passing. Can you provide a failing test for this issue ?

anilmaurya avatar Sep 04 '20 18:09 anilmaurya

the test is actually failing on platforms where sizeof(long) != 32 like Windows.

# Running:

.......F..

Finished in 0.176423s, 56.6819 runs/s, 113.3638 assertions/s.

  1) Failure:
FastJsonparserTest#test_large_integer_parsing [c:/moje/gem/fast_jsonparser/test/fast_jsonparser_test.rb:83]:
Expected: -601754617
  Actual: 7386425359

ahorek avatar Jul 30 '23 22:07 ahorek