]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
libstdc++: Fix std::random_device for avr
authorJonathan Wakely <jwakely@redhat.com>
Tue, 31 Jan 2023 22:28:16 +0000 (22:28 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 16 Mar 2023 16:23:19 +0000 (16:23 +0000)
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)

libstdc++-v3/src/c++11/random.cc

index 44b9f30e4a9930bfb6c25b114a98bd558f939c99..f2dc5f3021ff759997eead2670523dc88c0ef1af 100644 (file)
@@ -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