aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-08-11 18:10:29 +0100
committerJonathan Wakely <jwakely@redhat.com>2023-08-11 18:20:48 +0100
commit9e33d71834416b7eddadae2b0f68e85f04cd0c7f (patch)
tree9788f08737983c7263cf0806c9441cfd1e9a5fba /libstdc++-v3/include
parent20db5cab7a5ca9ac2928d10efca85e80a3d8630b (diff)
downloadgcc-9e33d71834416b7eddadae2b0f68e85f04cd0c7f.zip
gcc-9e33d71834416b7eddadae2b0f68e85f04cd0c7f.tar.gz
gcc-9e33d71834416b7eddadae2b0f68e85f04cd0c7f.tar.bz2
libstdc++: Do not call log10(0.0) in std::format [PR110860]
Calling log10(0.0) returns -inf which has undefined behaviour when converted to an integer. We only need to use log10 for large values anyway. If the value is zero then the larger buffer is only needed due to a large precision, so we don't need to use log10 to estimate the number of digits for the significand. libstdc++-v3/ChangeLog: PR libstdc++/110860 * include/std/format (__formatter_fp::format): Do not call log10 with zero values.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/std/format2
1 files changed, 1 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 2fe430f..23da6b0 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -1490,7 +1490,7 @@ namespace __format
// If the buffer is too small it's probably because of a large
// precision, or a very large value in fixed format.
size_t __guess = 8 + __prec;
- if (__fmt == chars_format::fixed) // +ddd.prec
+ if (__fmt == chars_format::fixed && __v != 0) // +ddd.prec
{
if constexpr (is_same_v<_Fp, float>)
__guess += __builtin_log10f(__v < 0.0f ? -__v : __v);