From 6d479d13ce351f8eee7ade49b1f397766fe90209 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 02:41:44 +0200 Subject: [PATCH] Test the overflow check of json_view at the largest double Numbers of more than 19 digits at the boundary of the largest double are decided by the locale-aware fallback of the overflow check. Signed-off-by: Niels Lohmann --- tests/src/unit-json_view_builder.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/src/unit-json_view_builder.cpp b/tests/src/unit-json_view_builder.cpp index 4d2d3ffd8..ad44e9bc3 100644 --- a/tests/src/unit-json_view_builder.cpp +++ b/tests/src/unit-json_view_builder.cpp @@ -227,6 +227,17 @@ TEST_CASE("json_view builder") { check_same(text); } + + // the midpoint between the largest double and 2^1024 rounds to + // infinity (an overflow), one less to the largest double: with more + // than 19 digits, the fast conversions cannot decide these, and the + // overflow check falls back to strtod + const std::string midpoint = "179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792"; + const std::string below = "179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791"; + check_same(midpoint); + check_same("-" + midpoint); + check_same(below); + check_same("[" + below + "," + midpoint + "]"); } SECTION("malformed input")