[committed] libstdc++: Fix std::random_device for avr

Message ID 20230201210921.2445332-1-jwakely@redhat.com
State Committed
Commit 277dd6ea416718ba5493023b5a4660ecdbaf936c
Headers
Series [committed] libstdc++: Fix std::random_device for avr |

Commit Message

Jonathan Wakely Feb. 1, 2023, 9:09 p.m. UTC
  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(+)
  

Patch

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<FILE*>(_M_file));
 #endif
     _M_file = nullptr;
+#endif
   }
 
   random_device::result_type