Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22233

A specific Boost regex works fine, but if I use it inside a Boost unit test it crashes

$
0
0

Everything worked fine with my project when using Boost 1.58 and GCC4.9, after deciding to upgrade it to Boost 1.72 and GCC9 I have started to have this problem.

I've been looking into this for a while and at first I thought it was a problem with the code of my project but I have tested it outside with the following example and it still happens.

Basically, I have this code in a main:

std::string s = "45.125º";

const char* pattern = 
    "^\\s*(\\+|\\-)?\\s*""(?:(?:\\s*((?:[0-9]|\\.)+)(?:º|d|\\s+)))?""(?:(?:\\s*((?:[0-9]|\\.)+)(?:'|m|\\s+)))?""(?:(?:\\s*((?:[0-9]|\\.)+)(?:\"|s|\\s+)))?""\\s*$";

const boost::regex pieces_regex(pattern);
boost::cmatch pieces_match;
if(boost::regex_match(s.c_str(), pieces_match, pieces_regex, boost::match_default)) {
    std::cout << "Match"<< std::endl;
    for (auto piece : pieces_match) {
       std::cout << "Piece: "<< piece.str() << std::endl;
    }
}
else std::cout << "NOPE"<< std::endl;
std::cout << "DONE"<< std::endl;

If I include boost/regex.hpp and compile it with:

c++ regexTest.cpp -I $BOOST_ROOT/include/ $BOOST_ROOT/lib/libboost_regex-x64.so

Everything works fine, if I use a string that matches it matches and if I don't it doesn't, okay.

This is the result of the execution:

Match
Piece: 45.125º
Piece: 
Piece: 45.125
Piece: 
Piece:
DONE 

However, if I put this inside a Boost test:

BOOST_AUTO_TEST_SUITE (test_reg)
BOOST_AUTO_TEST_CASE (test_example)
{
exactly the same code as before
}
BOOST_AUTO_TEST_SUITE_END ()

And now include boost/test/included/unit_test.hpp and compile it with:

c++ regexTest.cpp -I $BOOST_ROOT/include/ $BOOST_ROOT/lib/libboost_regex-x64.so $BOOST_ROOT/lib/libboost_unit_test_framework-x64.so

It still works and the test is run, but this happens:

Running 1 test case...
Match
Piece: 45.125º
Piece: 
Piece: 45.125
Piece: 
Piece: 
DONE

*** No errors detected
corrupted size vs. prev_size in fastbins
Aborted (core dumped)

If I use a more simple reg expression, such as:

 const boost::regex pieces_regex("^[0-9]+$");

for example, nothing crashes despite being inside the test.

At first I thought it was a problem with my regex but it seems to work fine by itself (outside of a test) and have also tested it at https://regex101.com/.

I honestly have no idea of what else to try, I was starting to think maybe there was some kind of linkage error because I specified something wrong for CMake but the error still happens with this isolated example. Any idea of what could be going on here?

Note: The error happens in the same way inside my project (it executes fine and after saying "no errors" it crashes) but the message there is this one:

malloc_consolidate(): invalid chunk size
Aborted (core dumped)

Viewing all articles
Browse latest Browse all 22233

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>