From 954b73445cfbfef01207d51d1b986c6dd796c6d0 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 1 Apr 2019 15:22:15 +0200 Subject: Refine underflow check in QLocaleData::convertDoubleToFloat() A string can parse as a non-zero double that's smaller than the smallest float yet be a faithful representation of the smallest float. So rather than testing for non-zero doubles less than the smallest float, test for non-zero doubles that cast to float zero; these underflow. This means small values close below the smallest float shall round up to it, rather than down to zero, requiring a tweak to an existing test. Added a test for the boundary case (and tidied the test data). Fixes: QTBUG-74833 Change-Id: I4cb30b3c0e54683574b98253505607caaf88fbfb Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale_p.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index a96ecf1c1c..7487c9128c 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -252,10 +252,8 @@ public: const float huge = std::numeric_limits::infinity(); return d < 0 ? -huge : huge; } - if (std::fabs(d) >= std::numeric_limits::min() // i.e. d != 0 - && std::fabs(d) < std::numeric_limits::min()) { - // Values smaller than std::numeric_limits::min() have - // failed already; match them. + if (d != 0 && float(d) == 0) { + // Values that underflow double already failed. Match them: if (ok != 0) *ok = false; return 0; -- cgit v1.2.3