Boost C++ Libraries: Ticket #5198: 64 bit issue in address_v4::broadcast() with to_ulong() https://svn.boost.org/trac10/ticket/5198 <p> In address_v4.ipp:144 </p> <p> 142 address_v4 address_v4::broadcast(const address_v4&amp; addr, const address_v4&amp; mask) 143 { 144 return address_v4(addr.to_ulong() | ~mask.to_ulong()); 145 } </p> <p> 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. </p> <p> 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). </p> <p> Casting the return value from mask.to_ulong() to uint32_t before inverting it fixes this issue for me. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5198 Trac 1.4.3 arvid@… Thu, 17 Feb 2011 06:44:49 GMT <link>https://svn.boost.org/trac10/ticket/5198#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5198#comment:1</guid> <description> <p> The code snipped didn't end up as I intended, here it is again: </p> <pre class="wiki">142 address_v4 address_v4::broadcast(const address_v4&amp; addr, const address_v4&amp; mask) 143 { 144 return address_v4(addr.to_ulong() | ~mask.to_ulong()); 145 } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Mon, 06 Jun 2011 02:03:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5198#comment:2 https://svn.boost.org/trac10/ticket/5198#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Was fixed on release branch in <a class="changeset" href="https://svn.boost.org/trac10/changeset/68200" title="Merge from trunk: * Update copyright notice. * Version bump. * Fix ...">[68200]</a>. </p> Ticket