summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Persson <mikael.s.persson@gmail.com>2025-06-10 20:45:26 -0400
committerGitHub <noreply@github.com>2025-06-11 03:45:26 +0300
commit708fff700f36ab3c2ab107b984ec9f3b8be5f055 (patch)
treef485a3e4efb06de2d00239ec9097896eca04d1ef
parent2f35c28a52fd0ada7600273de9aacb66550bcdcb (diff)
downloadProject-Tick-708fff700f36ab3c2ab107b984ec9f3b8be5f055.tar.gz
Project-Tick-708fff700f36ab3c2ab107b984ec9f3b8be5f055.zip
Fixed undefined behavior with log10 cast of fractional doubles (#276)
-rw-r--r--include/toml++/impl/toml_formatter.inl2
-rw-r--r--toml.hpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/include/toml++/impl/toml_formatter.inl b/include/toml++/impl/toml_formatter.inl
index 201de9ce9e..8b4f633dca 100644
--- a/include/toml++/impl/toml_formatter.inl
+++ b/include/toml++/impl/toml_formatter.inl
@@ -91,7 +91,7 @@ TOML_ANON_NAMESPACE_START
weight += 1u;
val *= -1.0;
}
- return weight + static_cast<size_t>(log10(val)) + 1u;
+ return weight + static_cast<size_t>(abs(log10(val))) + 1u;
}
case node_type::boolean: return 5u;
diff --git a/toml.hpp b/toml.hpp
index ef3515b136..8fe1a0d5b8 100644
--- a/toml.hpp
+++ b/toml.hpp
@@ -17107,7 +17107,7 @@ TOML_ANON_NAMESPACE_START
weight += 1u;
val *= -1.0;
}
- return weight + static_cast<size_t>(log10(val)) + 1u;
+ return weight + static_cast<size_t>(abs(log10(val))) + 1u;
}
case node_type::boolean: return 5u;