[Boost-bugs] [Boost C++ Libraries] #5198: 64 bit issue in address_v4::broadcast() with to_ulong()

Subject: [Boost-bugs] [Boost C++ Libraries] #5198: 64 bit issue in address_v4::broadcast() with to_ulong()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-17 06:42:47


#5198: 64 bit issue in address_v4::broadcast() with to_ulong()
------------------------------+---------------------------------------------
 Reporter: arvid@… | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.44.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 In address_v4.ipp:144

 142 address_v4 address_v4::broadcast(const address_v4& addr, const
 address_v4& mask)
 143 {
 144 return address_v4(addr.to_ulong() | ~mask.to_ulong());
 145 }

 On a 64 bit build, where long is 64 bit, inverting the mask will generate
 a very large number (all the upper bits will be set). Once passed into the
 constructor of address_v4(), this fails the bound check and throws an
 exception.

 You might want to make to_ulong() always return uint32_t, or cast here
 (and in that case probably inspect all other places where to_ulong() is
 used).

 Casting the return value from mask.to_ulong() to uint32_t before inverting
 it fixes this issue for me.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5198>
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:05 UTC