[gcc r11-10579] libstdc++: Fix std::random_device for avr

Jonathan Wakely redi@gcc.gnu.org
Thu Mar 16 16:51:17 GMT 2023


https://gcc.gnu.org/g:f99b97015f16ee3d8d4656666cd7594555fafbf9

commit r11-10579-gf99b97015f16ee3d8d4656666cd7594555fafbf9
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 31 22:28:16 2023 +0000

    libstdc++: Fix std::random_device for avr
    
    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.
    
    (cherry picked from commit 277dd6ea416718ba5493023b5a4660ecdbaf936c)

Diff:
---
 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 44b9f30e4a9..f2dc5f3021f 100644
--- a/libstdc++-v3/src/c++11/random.cc
+++ b/libstdc++-v3/src/c++11/random.cc
@@ -395,6 +395,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
       }
 #endif
 
+#ifdef _GLIBCXX_USE_DEV_RANDOM
 #ifdef USE_POSIX_FILE_IO
     ::close(_M_fd);
     _M_fd = -1;
@@ -402,6 +403,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
     std::fclose(static_cast<FILE*>(_M_file));
 #endif
     _M_file = nullptr;
+#endif
   }
 
   random_device::result_type


More information about the Libstdc++-cvs mailing list