• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blues / note-c / 13187867177
93%

Build:
DEFAULT BRANCH: master
Ran 06 Feb 2025 09:10PM UTC
Jobs 1
Files 9
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

06 Feb 2025 09:05PM UTC coverage: 90.606%. Remained the same
13187867177

push

github

web-flow
TS-643: Fix 32-bit breakage in JSON_number_handling_test.cpp. (#178)

* TS-643: Fix 32-bit breakage in JSON_number_handling_test.cpp.

When Zak recently converted the unit tests to be compiled for 32-bit instead of
64-bit, this test mysteriously broke. Specifically, this scenario:

```
GIVEN("A JSON object with a numeric field with the max value of JINTEGER") {
    const char expected[] = "{\"" FIELD "\":" JINTEGER_MAX_STR "}";
    obj = JCreateObject();
    REQUIRE(obj != NULL);
    REQUIRE(JAddIntToObject(obj, FIELD, JINTEGER_MAX) != NULL);

    WHEN("JPrintUnformatted is called on that object") {
        char *out = JPrintUnformatted(obj);
        REQUIRE(out != NULL);

        THEN("The value is printed accurately") {
            CHECK(strcmp(expected, out) == 0);
        }

        JFree(out);
    }

    JDelete(obj);
}
```

JINTEGER_MAX is 9223372036854775807. After switching to 32-bit,
JPrintUnformatted was printing 9.2233720368547758e+18. The problem comes down
to the _print_number CJSON function, specifically this bit:

```
if (vnum != (JNUMBER)vint) {
    JNtoA(vnum, nbuf, -1);
} else {
    JItoA(vint, nbuf);
}
```

vnum is the JNUMBER (double) representation of the number stored in the JSON
object. vint is the integer representation. For 9223372036854775807, these two
values should be equal, and the JItoA should be taken. However, after the change
to 32-bit, the JNtoA branch was being taken instead, leading to the test
failure. ChatGPT has a good explanation for why this is happening:

1. `vnum` is `9.2233720368547758e+18` (a `double` value).
2. `vint` is `9223372036854775807` (which is `int64_t`, i.e., `0x7FFFFFFFFFFFFFFF`).
3. When compiled in **64-bit mode**, `vint` is converted to `double` using **strict 64-bit IEEE 754** rules, resulting in:
   ```
   (JNUMBER)vint == 9.2233720368547758e+18
   ```
   which exactly matches `vnum`, so the condition `vnum != (JNUMBER)vint` evaluates to **... (continued)

1069 of 1291 branches covered (82.8%)

Branch coverage included in aggregate %.

2220 of 2339 relevant lines covered (94.91%)

82.16 hits per line

Jobs
ID Job ID Ran Files Coverage
1 13187867177.1 06 Feb 2025 09:10PM UTC 9
90.61
GitHub Action Run
Source Files on build 13187867177
  • Tree
  • List 9
  • Changed 2
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • 8bac476c on github
  • Prev Build on master (#13167278142)
  • Next Build on master (#13286899753)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc