From: Jonathan Wakely Date: Wed, 24 May 2017 19:27:28 +0000 (+0100) Subject: Use CHAR_BIT instead of assuming 8 bits X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b6784361760fc9d456b6deb8dcf8715b573bcb9e;p=gcc.git Use CHAR_BIT instead of assuming 8 bits * src/c++11/random.cc (random_device::_M_getentropy): Use __CHAR_BIT__ instead of fixed number of bits. From-SVN: r248428 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 24555d3f672..af0b472280a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2017-05-24 Jonathan Wakely + + * src/c++11/random.cc (random_device::_M_getentropy): Use __CHAR_BIT__ + instead of fixed number of bits. + 2017-05-24 Andreas Schwab * config/abi/post/ia64-linux-gnu/baseline_symbols.txt: Update. diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index 5011cf2bb6b..ef17223ac0b 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -187,8 +187,9 @@ namespace std _GLIBCXX_VISIBILITY(default) if (ent < 0) return 0.0; - if (static_cast(ent) > sizeof(result_type) * 8) - return static_cast(sizeof(result_type) * 8); + const int max = sizeof(result_type) * __CHAR_BIT__; + if (ent > max) + ent = max; return static_cast(ent); #else