From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 32B0D3858D20; Fri, 11 Aug 2023 17:21:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32B0D3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691774513; bh=fJsiYI3ztToSiVhlAMtHLnEEeiZxQotPsJd2qHW4NwE=; h=From:To:Subject:Date:From; b=nhAb2EVXptuxEFbfTIdys32g5lhLBHKVg4HdmFucKJSjXjojZFJlS5FsBWuLs4MlG G66iUP5BCeU3ApApWwMo3NhgcUIuBQTEyeFtDssMr7yq+wrvNmwVYk9CPSYiYVxK2a MEuJr9IZf94I7R+sZ5N2+xmRQUPROZygBuIO/eME= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-3159] libstdc++: Do not call log10(0.0) in std::format [PR110860] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 20db5cab7a5ca9ac2928d10efca85e80a3d8630b X-Git-Newrev: 9e33d71834416b7eddadae2b0f68e85f04cd0c7f Message-Id: <20230811172153.32B0D3858D20@sourceware.org> Date: Fri, 11 Aug 2023 17:21:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9e33d71834416b7eddadae2b0f68e85f04cd0c7f commit r14-3159-g9e33d71834416b7eddadae2b0f68e85f04cd0c7f Author: Jonathan Wakely Date: Fri Aug 11 18:10:29 2023 +0100 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. Diff: --- libstdc++-v3/include/std/format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 2fe430f75f69..23da6b008c5d 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);