[Boost-bugs] [Boost C++ Libraries] #12401: UB when sizeof(std::size_t) in floor_log2

Subject: [Boost-bugs] [Boost C++ Libraries] #12401: UB when sizeof(std::size_t) in floor_log2
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-08-19 16:19:19


#12401: UB when sizeof(std::size_t) in floor_log2
------------------------------+------------------------
 Reporter: viboes | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: intrusive
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: |
------------------------------+------------------------
 The line

 {{{
       v |= v >> 32; // (*)

 }}}

 in the following function, should fall in UB, when the sizeof(std::size_t)
 is 4, isn't it?


 {{{
    inline std::size_t floor_log2 (std::size_t v,
 integral_constant<std::size_t, 64>)
    {
       static const std::size_t MultiplyDeBruijnBitPosition[64] = {
       63, 0, 58, 1, 59, 47, 53, 2,
       60, 39, 48, 27, 54, 33, 42, 3,
       61, 51, 37, 40, 49, 18, 28, 20,
       55, 30, 34, 11, 43, 14, 22, 4,
       62, 57, 46, 52, 38, 26, 32, 41,
       50, 36, 17, 19, 29, 10, 13, 21,
       56, 45, 25, 31, 35, 16, 9, 12,
       44, 24, 15, 8, 23, 7, 6, 5};

       v |= v >> 1;
       v |= v >> 2;
       v |= v >> 4;
       v |= v >> 8;
       v |= v >> 16;
       v |= v >> 32; // (*)
       return MultiplyDeBruijnBitPosition[((std::size_t)((v - (v >>
 1))*0x07EDD5E59A4E28C2ULL)) >> 58];
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12401>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC