I am trying to execute following code which extracts the email address from the string. I am getting segmentation fault.
// A.cpp
#include <boost/algorithm/string/trim.hpp>
#include <boost/regex.hpp>
#include<iostream>
int main()
{
std::string rcptAddress("3J1eg==?= <dummyemail@edummyemail.com>");
boost::regex exp("\\s", boost::regex::icase|boost::regex::perl);
std::string fmt("");
rcptAddress = boost::regex_replace(rcptAddress, exp, fmt);
std::cout << rcptAddress << std::endl;
exp.assign(".*<(.*)>.*");
fmt = "$1";
rcptAddress = boost::regex_replace(rcptAddress, exp, fmt);
std::cout << rcptAddress << std::endl;
return 0;
}
I compiled the code with following switches:
g++ A.cpp -g -O2 -Wall -Werror -fmessage-length=0 -fno-strict-aliasing -DBOOST_DISABLE_THREADS -finline-functions -L /root/.local/8.0.0-gcc4.1.2/lib/ -I /root/.local/8.0.0-gcc4.1.2/include/boost-1_39/ -lboost_regex-gcc41-mt-1_39
When I execute the binary, I get SEGMENTATION FAULT as follows
LD_LIBRARY_PATH=/root/.local/8.0.0-gcc4.1.2/lib/ ./a.out
3J1eg==?=<dummyemail@edummyemail.com>
Segmentation fault
Recompiling the binary omitting -DBOOST_DISABLE_THREADS gave me the CORRECT results.
g++ A.cpp -g -O2 -Wall -Werror -fmessage-length=0 -fno-strict-aliasing -finline-functions -L /root/.local/8.0.0-gcc4.1.2/lib/ -I /root/.local/8.0.0-gcc4.1.2/include/boost-1_39/ -lboost_regex-gcc41-mt-1_39
I also tried putting in -DBOOST_DISABLE_THREADS and ommiting -finline-functions switch. Executing this binary also gave me the CORRECT results.
g++ A.cpp -g -O2 -Wall -Werror -fmessage-length=0 -fno-strict-aliasing -DBOOST_DISABLE_THREADS -L /root/.local/8.0.0-gcc4.1.2/lib/ -I /root/.local/8.0.0-gcc4.1.2/include/boost-1_39/ -lboost_regex-gcc41-mt-1_39
I am not able to find out why giving both the command line switches -DBOOST_DISABLE_THREADS and -finline-functions(which got added in optimization level -O3) causes the segfault here.
Any help would be great!
I am using g++ 4.1.2 on 64 bit CentOS 5.8. Boost library version is boost_1_39.
Thanks.