vivkin / gason

Lightweight and fast JSON parser for C++
MIT License
338 stars 51 forks source link

ival computation error on 32bit systems #12

Closed attilaz closed 9 years ago

attilaz commented 9 years ago

In this line https://github.com/vivkin/gason/blob/master/src/gason.h#L33 on 32 bit systems If payload's highest bit is set eg ( 0x8015b678 ) then (uint64_t)payload == 0xffffffff8015b678 so the payload bits overwrites the tags and nan_mask.

masking the result of ((uint64_t)payload) solves the issue. ival = JSON_VALUE_NAN_MASK | ((uint64_t)tag << JSON_VALUE_TAG_SHIFT) | (((uint64_t)payload)&JSON_VALUE_PAYLOAD_MASK)

I tested this on win32 and android (32bit).

vivkin commented 9 years ago

https://github.com/vivkin/gason/commit/23a1ebd37266dd8aa12d3bb920b0b7c75418defc casting payload to uintptr_t fix the issue, without additional operations.

attilaz commented 9 years ago

thanks for the fix