Boost C++ Libraries: Ticket #8612: unused pointers in copying of handlers https://svn.boost.org/trac10/ticket/8612 <p> boost/asio/detail/reactive_socket_recv_op.hpp: </p> <pre class="wiki"> 84 static void do_complete(io_service_impl* owner, operation* base, 85 const boost::system::error_code&amp; /*ec*/, 86 std::size_t /*bytes_transferred*/) 87 { 88 // Take ownership of the handler object. 89 reactive_socket_recv_op* o(static_cast&lt;reactive_socket_recv_op*&gt;(base)); CID 11125 (2): Unused pointer value (UNUSED_VALUE) CID 10926 (#1 of 1): Unused pointer value (UNUSED_VALUE) returned_pointer: Pointer "p.h" returned by "addressof(o-&gt;handler_)" is never used. 90 ptr p = { boost::addressof(o-&gt;handler_), o, o }; 91 92 BOOST_ASIO_HANDLER_COMPLETION((o)); 93 94 // Make a copy of the handler so that the memory can be deallocated before 95 // the upcall is made. Even if we're not about to make an upcall, a 96 // sub-object of the handler may be the true owner of the memory associated 97 // with the handler. Consequently, a local copy of the handler is required 98 // to ensure that any owning sub-object remains valid until after we have 99 // deallocated the memory here. 100 detail::binder2&lt;Handler, boost::system::error_code, std::size_t&gt; 101 handler(o-&gt;handler_, o-&gt;ec_, o-&gt;bytes_transferred_); 102 p.h = boost::addressof(handler.handler_); 103 </pre><p> boost/asio/detail/reactive_socket_send_op.hpp: </p> <pre class="wiki"> 81 static void do_complete(io_service_impl* owner, operation* base, 82 const boost::system::error_code&amp; /*ec*/, 83 std::size_t /*bytes_transferred*/) 84 { 85 // Take ownership of the handler object. 86 reactive_socket_send_op* o(static_cast&lt;reactive_socket_send_op*&gt;(base)); CID 11126 (4): Unused pointer value (UNUSED_VALUE) CID 11126 (4): Unused pointer value (UNUSED_VALUE) CID 10927 (#2 of 2): Unused pointer value (UNUSED_VALUE) CID 10927 (#1 of 2): Unused pointer value (UNUSED_VALUE) returned_pointer: Pointer "p.h" returned by "addressof(o-&gt;handler_)" is never used. 87 ptr p = { boost::addressof(o-&gt;handler_), o, o }; 88 89 BOOST_ASIO_HANDLER_COMPLETION((o)); 90 91 // Make a copy of the handler so that the memory can be deallocated before 92 // the upcall is made. Even if we're not about to make an upcall, a 93 // sub-object of the handler may be the true owner of the memory associated 94 // with the handler. Consequently, a local copy of the handler is required 95 // to ensure that any owning sub-object remains valid until after we have 96 // deallocated the memory here. 97 detail::binder2&lt;Handler, boost::system::error_code, std::size_t&gt; 98 handler(o-&gt;handler_, o-&gt;ec_, o-&gt;bytes_transferred_); 99 p.h = boost::addressof(handler.handler_); </pre><p> boost/asio/detail/wait_handler.cpp: </p> <pre class="wiki">43 static void do_complete(io_service_impl* owner, operation* base, 44 const boost::system::error_code&amp; /*ec*/, 45 std::size_t /*bytes_transferred*/) 46 { 47 // Take ownership of the handler object. 48 wait_handler* h(static_cast&lt;wait_handler*&gt;(base)); CID 11127 (2): Unused pointer value (UNUSED_VALUE) CID 10929: Unused pointer value (UNUSED_VALUE) CID 10928 (#1 of 1): Unused pointer value (UNUSED_VALUE) returned_pointer: Pointer "p.h" returned by "addressof(h-&gt;handler_)" is never used. 49 ptr p = { boost::addressof(h-&gt;handler_), h, h }; 50 51 BOOST_ASIO_HANDLER_COMPLETION((h)); 52 53 // Make a copy of the handler so that the memory can be deallocated before 54 // the upcall is made. Even if we're not about to make an upcall, a 55 // sub-object of the handler may be the true owner of the memory associated 56 // with the handler. Consequently, a local copy of the handler is required 57 // to ensure that any owning sub-object remains valid until after we have 58 // deallocated the memory here. 59 detail::binder1&lt;Handler, boost::system::error_code&gt; 60 handler(h-&gt;handler_, h-&gt;ec_); 61 p.h = boost::addressof(handler.handler_); </pre><p> boost/asio/detail/wait_handler.cpp: </p> <pre class="wiki">43 static void do_complete(io_service_impl* owner, operation* base, 44 const boost::system::error_code&amp; /*ec*/, 45 std::size_t /*bytes_transferred*/) 46 { 47 // Take ownership of the handler object. 48 wait_handler* h(static_cast&lt;wait_handler*&gt;(base)); CID 11127 (2): Unused pointer value (UNUSED_VALUE) CID 10928: Unused pointer value (UNUSED_VALUE) CID 10929 (#1 of 1): Unused pointer value (UNUSED_VALUE) returned_pointer: Pointer "p.h" returned by "addressof(h-&gt;handler_)" is never used. 49 ptr p = { boost::addressof(h-&gt;handler_), h, h }; 50 51 BOOST_ASIO_HANDLER_COMPLETION((h)); 52 53 // Make a copy of the handler so that the memory can be deallocated before 54 // the upcall is made. Even if we're not about to make an upcall, a 55 // sub-object of the handler may be the true owner of the memory associated 56 // with the handler. Consequently, a local copy of the handler is required 57 // to ensure that any owning sub-object remains valid until after we have 58 // deallocated the memory here. 59 detail::binder1&lt;Handler, boost::system::error_code&gt; 60 handler(h-&gt;handler_, h-&gt;ec_); 61 p.h = boost::addressof(handler.handler_); </pre><p> boost/asio/ </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8612 Trac 1.4.3 chris_kohlhoff Fri, 24 May 2013 02:33:52 GMT severity changed https://svn.boost.org/trac10/ticket/8612#comment:1 https://svn.boost.org/trac10/ticket/8612#comment:1 <ul> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Cosmetic</span> </li> </ul> <p> I suspect the warning is spurious, as the member h is used by ptr's destructor. Will investigate later. </p> Ticket Richard <legalize@…> Fri, 24 May 2013 03:14:10 GMT <link>https://svn.boost.org/trac10/ticket/8612#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8612#comment:2</guid> <description> <p> I looked at this pretty closely before opening the ticket. So far, Coverity has had a very low false positive on it's analysis because it analyzes the resulting binary as well as the source code. </p> <p> To my eyes, the sequence goes like this in reactive_socket_recv_op.hpp: </p> <pre class="wiki">ptr p = { boost::addressof(o-&gt;handler_), o, o }; // p.h == boost::addressof(o-&gt;handler_) BOOST_ASIO_HANDLER_COMPLETION((o)); // p.h == boost::addressof(o-&gt;handler_) detail::binder2&lt;Handler, boost::system::error_code, std::size_t&gt; handler(o-&gt;handler_, o-&gt;ec_, o-&gt;bytes_transferred_); // p.h == boost::addressof(o-&gt;handler_) p.h = boost::asio::detail::addressof(handler.handler_); // p.h overwritten and original value discarded p.reset(); // p.h used in d'tor if p.v != 0 </pre><p> All the other cases I looked at appeared to follow a similar pattern, but I only drilled through the exact details on this one. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Fri, 24 May 2013 03:20:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8612#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8612#comment:3</guid> <description> <p> Doesn't seem to consider the possibility of exceptions. </p> </description> <category>Ticket</category> </item> <item> <author>Richard <legalize@…></author> <pubDate>Fri, 24 May 2013 12:03:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8612#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8612#comment:4</guid> <description> <p> If no exception is thrown, then the code executes as above. </p> </description> <category>Ticket</category> </item> <item> <author>Jeffrey Walton <noloader@…></author> <pubDate>Thu, 25 Jul 2013 06:22:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8612#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8612#comment:5</guid> <description> <p> Coverity offers its scanning service gratis to open and free projects. Boost can sign up for an account at <a class="ext-link" href="http://scan.coverity.com/projects"><span class="icon">​</span>http://scan.coverity.com/projects</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>