Boost C++ Libraries: Ticket #6361: integer overflow in boost::chrono::process_real_cpu_clock::now() under Windows 32bits https://svn.boost.org/trac10/ticket/6361 <p> As of 1.48 Boost.Chrono contains code below for boost::chrono::process_real_cpu_clock::now() (boost\chrono\detail\inlined\win\process_cpu_clocks.hpp) </p> <blockquote> <p> clock_t c = ::clock(); /* ... */ return time_point( </p> <blockquote> <p> duration(c*(1000000000l/CLOCKS_PER_SEC)) </p> </blockquote> <p> ); </p> </blockquote> <p> duration::rep is int64/nanoseconds, clock_t is long. This is under VS2008, Win XP 32bits. I think "c" should be cast to duration::rep before being multiplied. </p> <p> C-style cast fixed the problem for me. Howard Hinnant suggested following cleaner fix on the mailing list : </p> <p> typedef ratio_divide&lt;giga, ratio&lt;CLOCKS_PER_SEC&gt;&gt;::type R; return time_point( </p> <blockquote> <p> duration(static_cast&lt;rep&gt;(c)*R::num/R::den) </p> </blockquote> <p> ); </p> <p> NB: This appears at least twice in this file. It also appears in "mac" and "posix" folders though I cannot say if it is problematic on this platforms. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6361 Trac 1.4.3 viboes Wed, 21 Mar 2012 00:53:55 GMT status, milestone changed https://svn.boost.org/trac10/ticket/6361#comment:1 https://svn.boost.org/trac10/ticket/6361#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Sorry, I forget this issue. I will take care of it as soon as I have access to a windows machine. </p> Ticket viboes Sun, 25 Mar 2012 17:04:22 GMT attachment set https://svn.boost.org/trac10/ticket/6361 https://svn.boost.org/trac10/ticket/6361 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">6361.patch</span> </li> </ul> Ticket viboes Sun, 25 Mar 2012 19:44:15 GMT <link>https://svn.boost.org/trac10/ticket/6361#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6361#comment:2</guid> <description> <p> Committed in trunk At revision: <a class="changeset" href="https://svn.boost.org/trac10/changeset/77545" title="Chrono: Apply patch 6361: integer overflow in ...">[77545]</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 01 Apr 2012 19:28:19 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6361#comment:3 https://svn.boost.org/trac10/ticket/6361#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/77694" title="Chrono Fix #6361,#6628,#6666">[77694]</a>) Chrono Fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6361" title="#6361: Bugs: integer overflow in boost::chrono::process_real_cpu_clock::now() under ... (closed: fixed)">#6361</a>,<a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6628" title="#6628: Bugs: compiler warning in process_cpu_clocks.hpp (closed: fixed)">#6628</a>,<a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6666" title="#6666: Bugs: thread_clock.hpp needs pthread.h (closed: fixed)">#6666</a> </p> Ticket