From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 163EF3858CD1 for ; Fri, 11 Aug 2023 17:22:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 163EF3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691774545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y7Ze5k0W6EaaniTTkg71HY06FsWQXDaqf3MH6F7D3no=; b=Z1Q48iYAYSc8ApsJ9cSeBEZc7UtMqu9f3h3/ihvVgqyU1xGthFGyEGP91OqnqMk3SMDvdx 3BOTZqvBvNQ8eODs6OW0Ght0W9aGLQ5LPlMA4y8lPoCZ2vyphfHVWRp566pw2Rpa8bK2eH w75CmaUa0E7PBycIZ74eaDjwAXNceYI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-290-qtzTLuEbNWa8k3EPwTT5qg-1; Fri, 11 Aug 2023 13:22:22 -0400 X-MC-Unique: qtzTLuEbNWa8k3EPwTT5qg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7AB84101A5B4; Fri, 11 Aug 2023 17:22:22 +0000 (UTC) Received: from localhost (unknown [10.39.192.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 384A8492B0F; Fri, 11 Aug 2023 17:22:22 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Do not call log10(0.0) in std::format [PR110860] Date: Fri, 11 Aug 2023 18:21:53 +0100 Message-ID: <20230811172221.1432932-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Second attempt to fix this PR. Tested x86_64-linux, pushed to trunk. -- >8 -- 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. --- 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 2fe430f75f6..23da6b008c5 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); -- 2.41.0