ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.04k stars 262 forks source link

Cannot read specific JSON input when compiled for 32-bit #85

Closed lnkuiper closed 2 years ago

lnkuiper commented 2 years ago

Describe the bug When compiled with flag -m32 reading the following JSON returns NULL. Reading is fine when compiling for 64-bit.

{
    "firstName": "John",
    "lastName": "Smith",
    "isAlive": true,
    "age": 25,
    "address": {
      "streetAddress": "21 2nd Street",
      "city": "New York",
      "state": "NY",
      "postalCode": "10021-3100"
    },
    "phoneNumbers": [
      {
        "type": "home",
        "number": "212 555-1234"
      },
      {
        "type": "office",
        "number": "646 555-4567"
      }
    ],
    "children": [],
    "spouse": null
    }

Your environment

Additional context DuckDB uses yyjson for its JSON extension. We had no issues with this specific JSON string before (it is part of our tests). I updated yyjson to the latest version, and this issue occurred.

ibireme commented 2 years ago

I haven't tested 32bit C++ compilation in CI, maybe there will be bugs. I'll investigate later.

ibireme commented 2 years ago

@lnkuiper I tested many combinations of compile flags and failed to reproduce the bug, until I changed yyjson.c to yyjson.cpp and used the same flags from duckdb CI workflow.

The problem is with this combined flags: g++-5 -m32 -fPIC. When using these flags, both reader and writer test cases in yyjson will fail. But everything works fine if I use gcc-5 or a higher version of gcc/g++, or remove the -m32/-fPIC flag.

It seems that the __asm hint code in the read_number() function is causing the specific error. I removed this line of code in the latest version.

lnkuiper commented 2 years ago

@ibireme Fixing 32-bit bugs is the worst.

Thank you so much for taking the time to do this, and again thank you so much for this project!