Boost C++ Libraries: Ticket #8925: libs/log/src/event.cpp: might not retireve last error correctly https://svn.boost.org/trac10/ticket/8925 <p> The following code may not retrieve the last error correctly. </p> <p> if (<a class="missing wiki">WaitForSingleObject</a>(m_event, INFINITE) != 0) { </p> <blockquote> <p> BOOST_THROW_EXCEPTION(system::system_error( </p> <blockquote> <p> <a class="missing wiki">GetLastError</a>(), system::system_category(), "Failed to block on Windows event")); </p> </blockquote> </blockquote> <p> } </p> <p> If the compile evaluates the args in BOOST_THROW_EXCEPTION from left to right, system::system_error could call on a Win32 API that blows away the error. Conversely, if the args are evaluated right to left, then system::system_category() or the "Failed to block on Windows event" string could cause last error to get blown away. </p> <p> My apologies for the write-up. After looking at a number of uses of <a class="missing wiki">WaitForSingleObject</a> in Boost, this is one of the few (fewer than 5) that is correct. </p> <p> Perhaps something like below would be easier to audit for correctness: </p> <p> if (<a class="missing wiki">WaitForSingleObject</a>(m_event, INFINITE) != 0) { </p> <blockquote> <p> DWORD dwError = <a class="missing wiki">GetLastError</a>(); BOOST_THROW_EXCEPTION(system::system_error( </p> <blockquote> <p> dwError, system::system_category(), "Failed to block on Windows event")); </p> </blockquote> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8925 Trac 1.4.3 Andrey Semashev Sat, 03 Aug 2013 11:37:09 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8925#comment:1 https://svn.boost.org/trac10/ticket/8925#comment:1 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/85198" title="GetLastError and errno usage made more reliable. Fixes #8925.">[85198]</a>) <a class="missing wiki">GetLastError</a> and errno usage made more reliable. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8925" title="#8925: Bugs: libs/log/src/event.cpp: might not retireve last error correctly (closed: fixed)">#8925</a>. </p> Ticket