Use CHAR_BIT instead of assuming 8 bits
authorJonathan Wakely <jwakely@redhat.com>
Wed, 24 May 2017 19:27:28 +0000 (20:27 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 24 May 2017 19:27:28 +0000 (20:27 +0100)
* src/c++11/random.cc (random_device::_M_getentropy): Use __CHAR_BIT__
instead of fixed number of bits.

From-SVN: r248428

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

index 24555d3f672d122e4b3fba314bffce2cdf1f5c90..af0b472280aade30570fdf8ad0b83619ad877ce8 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-24  Jonathan Wakely  <jwakely@redhat.com>
+
+       * src/c++11/random.cc (random_device::_M_getentropy): Use __CHAR_BIT__
+       instead of fixed number of bits.
+
 2017-05-24  Andreas Schwab  <schwab@suse.de>
 
        * config/abi/post/ia64-linux-gnu/baseline_symbols.txt: Update.
index 5011cf2bb6b720df4f41c748cb80ca87d974eb19..ef17223ac0b01fd71a4460822670e9c3a6d006f4 100644 (file)
@@ -187,8 +187,9 @@ namespace std _GLIBCXX_VISIBILITY(default)
     if (ent < 0)
       return 0.0;
 
-    if (static_cast<unsigned>(ent) > sizeof(result_type) * 8)
-      return static_cast<double>(sizeof(result_type) * 8);
+    const int max = sizeof(result_type) * __CHAR_BIT__;
+    if (ent > max)
+      ent = max;
 
     return static_cast<double>(ent);
 #else