Commit d6a5e5d
committed
fix: accept subnormal and underflowing doubles when parsing (#1427)
decodeDouble parsed numbers via `istringstream >> double`. For a
subnormal value such as `3.2114e-312`, operator>> sets failbit even
though it consumed the whole token and produced the correctly-rounded
value. The failure path only special-cased overflow (value ==
max/lowest), so subnormals were rejected as "not a number" -- meaning a
value jsoncpp had just serialized could fail to parse back.
In the failure path, distinguish a complete-but-out-of-range parse from
genuine junk by whether the entire token was consumed (is.eof()): on a
full parse keep the value operator>> produced (the correctly-rounded
subnormal, zero on underflow, or infinity on overflow); only a partial
parse (e.g. "1abc") is still rejected. eof() is used instead of errno
because it is a fundamental streambuf signal that behaves consistently
across libstdc++, libc++, and MSVC. Applied to both Reader and OurReader.
Adds CharReaderTest/parseSubnormalAndUnderflow covering subnormals, a
writer round-trip, underflow-to-zero, and continued rejection of junk.1 parent 5f1f240 commit d6a5e5d
2 files changed
Lines changed: 55 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
588 | 593 | | |
589 | 594 | | |
590 | 595 | | |
| |||
1637 | 1642 | | |
1638 | 1643 | | |
1639 | 1644 | | |
1640 | | - | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
1641 | 1651 | | |
1642 | 1652 | | |
1643 | 1653 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3212 | 3212 | | |
3213 | 3213 | | |
3214 | 3214 | | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
3215 | 3258 | | |
3216 | 3259 | | |
3217 | 3260 | | |
| |||
0 commit comments