Boost C++ Libraries: Ticket #9734: Wrong check of mmap() return value in coroutine stack allocator https://svn.boost.org/trac10/ticket/9734 <p> In boost source /libs/coroutine/detail/standard_stack_allocator_posix.cpp:120, it has the following snippet: </p> <div class="wiki-code"><div class="code"><pre> <span class="kt">void</span> <span class="o">*</span> <span class="n">limit</span> <span class="o">=</span> <span class="cp"># if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)</span> <span class="o">::</span><span class="n">mmap</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size_</span><span class="p">,</span> <span class="n">PROT_READ</span> <span class="o">|</span> <span class="n">PROT_WRITE</span><span class="p">,</span> <span class="n">MAP_PRIVATE</span> <span class="o">|</span> <span class="n">MAP_ANON</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="cp"># else</span> <span class="o">::</span><span class="n">mmap</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size_</span><span class="p">,</span> <span class="n">PROT_READ</span> <span class="o">|</span> <span class="n">PROT_WRITE</span><span class="p">,</span> <span class="n">MAP_PRIVATE</span><span class="p">,</span> <span class="n">fd</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="cp"># endif</span> <span class="o">::</span><span class="n">close</span><span class="p">(</span> <span class="n">fd</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span> <span class="o">!</span> <span class="n">limit</span><span class="p">)</span> <span class="n">throw</span> <span class="n">std</span><span class="o">::</span><span class="n">bad_alloc</span><span class="p">();</span> </pre></div></div><p> It assumes that mmap() returns 0 on fail. However when mmap() fails, the return value is NOT 0, but (void*)-1 instead. This wrong check will bypass the throw and let the error pass down, leading to confusing error message seen by the user. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9734 Trac 1.4.3 olli Tue, 04 Mar 2014 06:21:15 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9734#comment:1 https://svn.boost.org/trac10/ticket/9734#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> test against MAP_FAILED added, thx </p> Ticket