From ca14540bd01ce792b1fc43add8502059ac71835c Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky Date: Thu, 27 Jun 2024 13:10:20 -0500 Subject: [PATCH] Fixing real precision by limiting precision to 15 digits. (#8355) Fixes #8301 The previous fix was incomplete -- there were still some numbers that were being improperly converted into string. This fix limits double-to-string conversion to significant digits only, without an extra non-significant digit. --- osquery/utils/conversions/castvariant.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/osquery/utils/conversions/castvariant.h b/osquery/utils/conversions/castvariant.h index 319d3c6702a..4dbd55861c0 100644 --- a/osquery/utils/conversions/castvariant.h +++ b/osquery/utils/conversions/castvariant.h @@ -28,7 +28,13 @@ class CastVisitor : public boost::static_visitor { std::string operator()(const double& d) const { std::ostringstream ss; - ss << std::setprecision(std::numeric_limits::digits10 + 1) << d; + // SQLite supports 15 significant digits. + // The value of std::numeric_limits::digits10 is the number of base-10 + // digits that can be represented by the type T without change, that is, any + // number with this many significant decimal digits can be converted to a + // value of type T and back to decimal form, without change due to rounding + // or overflow. (from cppreference.com) + ss << std::setprecision(std::numeric_limits::digits10) << d; std::string s = ss.str(); if (s.find('.') == std::string::npos) { s += ".0";