Boost C++ Libraries: Ticket #9585: program_option::environment_iterator moves past terminating NULL pointer https://svn.boost.org/trac10/ticket/9585 <p> The get() method increments m_environment outside of the else scope: </p> <blockquote> <p> void get() { </p> <blockquote> <p> if (*m_environment == 0) </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> found_eof(); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> else { </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> std::string s(*m_environment); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> std::string::size_type n = s.find('='); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> assert(n != s.npos); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> value().first = s.substr(0, n); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> value().second = s.substr(n+1); </p> </blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> ++m_environment; </p> </blockquote> <p> } </p> </blockquote> <p> This means the iterator will move past the terminating pointer. A simple fix seems to include the increment in the else's scope. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9585 Trac 1.4.3 Vladimir Prus Mon, 20 Jan 2014 05:36:41 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9585#comment:1 https://svn.boost.org/trac10/ticket/9585#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> Fixed in <a class="ext-link" href="https://github.com/boostorg/program_options/commit/f50b02750a7b17ec6a149c0264bef5727a8df1f6"><span class="icon">​</span>https://github.com/boostorg/program_options/commit/f50b02750a7b17ec6a149c0264bef5727a8df1f6</a> </p> <p> Did you see any practical issues as result of this? </p> Ticket abel@… Mon, 20 Jan 2014 06:02:55 GMT <link>https://svn.boost.org/trac10/ticket/9585#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9585#comment:2</guid> <description> <p> No, I did not. I noticed it when working on a dirty hack to get program_options to work with c++0x using Windows' <a class="missing wiki">GetEnvironmentStrings</a> where I consequently had to touch this routine. </p> <p> A segmentation fault might obviously occur when other codes doesn't just use the pointer semantics as get() is public, but that's probably not what's considered a practical issue. Thanks for the quick response tho! </p> </description> <category>Ticket</category> </item> </channel> </rss>