Boost C++ Libraries: Ticket #3460: Index out-of-bounds in match_regex with _GLIBCXX_DEBUG https://svn.boost.org/trac10/ticket/3460 <p> Compiling a program that uses match_regex using the -D_GLIBCXX_DEBUG results in an error indicating that an index was out of bounds. Compile the attached testcase with: </p> <pre class="wiki">g++ -g -O1 -D_GLIBCXX_DEBUG -lboost_regex -o regex regex.cpp </pre><p> Running it displays the following error: </p> <pre class="wiki">/usr/include/c++/4.3/debug/vector:237:error: attempt to subscript container with out-of-bounds index 2, but container only holds 2 elements. Objects involved in the operation: sequence "this" @ 0x0x7fff918bfa40 { type = NSt7__debug6vectorIN5boost9sub_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEEESaIS8_EEE; } Aborted </pre><p> A backtrace of this says: </p> <pre class="wiki">#0 0x00007fead68e6fb5 in raise () from /lib/libc.so.6 #1 0x00007fead68e8bc3 in abort () from /lib/libc.so.6 #2 0x00007fead712587c in __gnu_debug::_Error_formatter::_M_error () from /usr/lib/libstdc++.so.6 #3 0x0000000000408638 in std::__debug::vector&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt; &gt; &gt; &gt;::operator[] (this=0x7fffdf8e8a50, __n=2) at /usr/include/c++/4.3/debug/vector:237 #4 0x00000000004104d5 in boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::match_prefix (this=0x7fffdf8e6eb0) at /usr/local/include/boost/regex/v4/match_results.hpp:418 #5 0x0000000000410899 in boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::match_imp (this=0x7fffdf8e6eb0) at /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:207 #6 0x0000000000410b5d in boost::regex_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::string&gt; &gt; &gt;, char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt; (first=&lt;value optimized out&gt;, last=&lt;value optimized out&gt;, m=&lt;value optimized out&gt;, e=&lt;value optimized out&gt;, flags=&lt;value optimized out&gt;) at /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:180 #7 0x0000000000405d7c in main () at /usr/local/include/boost/regex/v4/regex_match.hpp:100 </pre><p> It appears that m_subs<a class="changeset" href="https://svn.boost.org/trac10/changeset/2" title="Add Boost Disclaimer">[2]</a> is used in line 418 of match_results.hpp, but the size of m_subs is only 2. </p> <p> Compiling without -D_GLIBCXX_DEBUG allows the program to run, and valgrind does not detect any errors. I have tested this on the following platforms: </p> <pre class="wiki">Linux 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linux with g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3 (Ubuntu Jaunty) </pre><p> and </p> <pre class="wiki">Linux 2.6.31-9-generic #29-Ubuntu SMP Sun Aug 30 17:39:23 UTC 2009 i686 GNU/Linux with g++ (Ubuntu 4.4.1-4ubuntu1) 4.4.1 (Ubuntu Karmic) </pre><p> On Ubuntu Hardy with boost 1.34.1, the problem does not appear. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3460 Trac 1.4.3 Bart Janssens <bart.janssens@…> Thu, 17 Sep 2009 09:08:44 GMT attachment set https://svn.boost.org/trac10/ticket/3460 https://svn.boost.org/trac10/ticket/3460 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">regex.cpp</span> </li> </ul> <p> test program </p> Ticket John Maddock Fri, 18 Sep 2009 11:31:28 GMT <link>https://svn.boost.org/trac10/ticket/3460#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3460#comment:1</guid> <description> <p> I believe that if you build the regex library with -D_GLIBCXX_DEBUG as well then everything should be OK (it is on Ubuntu-9.0). </p> <p> Is mixing object files compiled with and without -D_GLIBCXX_DEBUG supposed to be OK? </p> </description> <category>Ticket</category> </item> <item> <author>Bart Janssens <bart.janssens@…></author> <pubDate>Fri, 18 Sep 2009 18:37:02 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3460#comment:2 https://svn.boost.org/trac10/ticket/3460#comment:2 <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">invalid</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3460#comment:1" title="Comment 1">johnmaddock</a>: </p> <blockquote class="citation"> <p> I believe that if you build the regex library with -D_GLIBCXX_DEBUG as well then everything should be OK (it is on Ubuntu-9.0). </p> <p> Is mixing object files compiled with and without -D_GLIBCXX_DEBUG supposed to be OK? </p> </blockquote> <p> My bad, I recompiled boost with -D_GLIBCXX_DEBUG and it's working fine now, thanks! </p> Ticket