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.129.124]) by sourceware.org (Postfix) with ESMTPS id 06E76385B506 for ; Wed, 1 Feb 2023 21:09:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06E76385B506 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=1675285781; 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=NXVAQx8kEd22IUz3sASlQsX1uhm+vh4ozpSKdb4hV34=; b=KWG2JGemietMXmx79Nk1bdYkORV0xpg6uerdc5hl9U+T8UGa0sHkOAWDIBKJ/eu8s8DHWc kINGcnJlzI5RAt6QLXuYJho5Xztom0Bu4HYNr/unbr5MrOTcSrx0dPIymGkj6jwDLHNXTH YNeI29ggSteHh+HeTT0QIBu7wUcTfR4= 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-153-hudp0t8oPWmmj_NYRJalow-1; Wed, 01 Feb 2023 16:09:23 -0500 X-MC-Unique: hudp0t8oPWmmj_NYRJalow-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D6D18027F5; Wed, 1 Feb 2023 21:09:22 +0000 (UTC) Received: from localhost (unknown [10.33.36.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 660F2112132C; Wed, 1 Feb 2023 21:09:22 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::random_device for avr Date: Wed, 1 Feb 2023 21:09:21 +0000 Message-Id: <20230201210921.2445332-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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_H2,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: Tested x86_64-linux, built on avr and msp430-elf. This should be backported to the affected branches. -- >8 -- This fixes a build failure that affects avr, but could affect other targets in theory. The _M_fini function should not try to use ::open or ::fopen if _GLIBCXX_USE_DEV_RANDOM is not defined, because no file can ever have been opened. libstdc++-v3/ChangeLog: * src/c++11/random.cc (random_device::_M_fini): Do not try to close the file handle if the target doesn't support the /dev/random and /dev/urandom files. --- libstdc++-v3/src/c++11/random.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index 9872e28b29d..ed2db4aef57 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -548,6 +548,7 @@ namespace std _GLIBCXX_VISIBILITY(default) } #endif +#ifdef _GLIBCXX_USE_DEV_RANDOM #ifdef USE_POSIX_FILE_IO ::close(_M_fd); _M_fd = -1; @@ -555,6 +556,7 @@ namespace std _GLIBCXX_VISIBILITY(default) std::fclose(static_cast(_M_file)); #endif _M_file = nullptr; +#endif } random_device::result_type -- 2.39.1