|
Boost Users : |
Subject: Re: [Boost-users] [regex] segfault from construction
From: Dmitry V. Krivenok (krivenok_at_[hidden])
Date: 2008-11-25 10:22:28
Andrew Troschinetz wrote:
> Hello all,
>
> I've got what I suspect is a relatively unique problem that's
> resulting in a segfault whenever I try to construct a boost::regex.
>
> First some machine information:
> Red Hat Enterprise Linux Server release 5.1 (Tikanga)
> Linux 2.6.18-53.el5, SMP, x86_64
> gcc 4.1.2 20070626 (Red Hat 4.1.2-14)
> boost 1.33.1-10
Hello!
I tested your example with the latest version of boost and also got
segfault.
krivenok_at_develop2 18:16:15 /tmp $ cat main.c
#include <boost/algorithm/string/regex.hpp>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input ("test test1 test2 test3");
string pattern ("\\btest\\b");
erase_regex (input, boost::regex (pattern));
cout << input << endl; // expecting " test1 test2 test3"
return 0;
}
krivenok_at_develop2 18:16:29 /tmp $ g++ --version
g++ (GCC) 4.1.2 (Gentoo 4.1.2 p1.1)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
krivenok_at_develop2 18:16:40 /tmp $ uname -a
Linux develop2 2.6.24-gentoo-r8 #1 SMP Tue Jul 15 02:59:02 MSD 2008 i686
Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz GenuineIntel GNU/Linux
krivenok_at_develop2 18:16:44 /tmp $ g++ -g -m32 -malign-double -O3 -Wall
-I/usr/local/dev/boost-1.37.0/include/
-L/usr/local/dev/boost-1.37.0/lib/ main.c -lboost_regex-gcc41-mt
krivenok_at_develop2 18:17:00 /tmp $
LD_LIBRARY_PATH=/usr/local/dev/boost-1.37.0/lib:$LD_LIBRARY_PATH ldd
./a.out
linux-gate.so.1 => (0xb7f34000)
libboost_regex-gcc41-mt-1_37.so.1.37.0 =>
/usr/local/dev/boost-1.37.0/lib/libboost_regex-gcc41-mt-1_37.so.1.37.0
(0xb7e61000)
libstdc++.so.6 =>
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libstdc++.so.6 (0xb7d61000)
libm.so.6 => /lib/libm.so.6 (0xb7d3b000)
libgcc_s.so.1 =>
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgcc_s.so.1 (0xb7d2f000)
libc.so.6 => /lib/libc.so.6 (0xb7bff000)
libicudata.so.38 => /usr/local/equipment/lib/libicudata.so.38
(0xb7127000)
libicui18n.so.38 => /usr/local/equipment/lib/libicui18n.so.38
(0xb6fc9000)
libicuuc.so.38 => /usr/local/equipment/lib/libicuuc.so.38
(0xb6ea4000)
librt.so.1 => /lib/librt.so.1 (0xb6e9b000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb6e84000)
/lib/ld-linux.so.2 (0xb7f35000)
krivenok_at_develop2 18:17:05 /tmp $
LD_LIBRARY_PATH=/usr/local/dev/boost-1.37.0/lib:$LD_LIBRARY_PATH ./a.out
Segmentation fault
krivenok_at_develop2 18:17:11 /tmp $
LD_LIBRARY_PATH=/usr/local/dev/boost-1.37.0/lib:$LD_LIBRARY_PATH gdb
./a.out
GNU gdb 6.7.1
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /tmp/a.out
warning: Lowest section in /usr/local/equipment/lib/libicudata.so.38 is
.hash at 000000f4
[Thread debugging using libthread_db enabled]
[New Thread 0xb6e9c6d0 (LWP 477)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6e9c6d0 (LWP 477)]
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char,
boost::cpp_regex_traits<char> > >::parse_extended (this=0xbfcff47c)
at
/usr/local/dev/boost-1.37.0/include/boost/regex/v4/basic_regex_parser.hpp:247
247 switch(this->m_traits.syntax_type(*m_position))
Current language: auto; currently c++
(gdb) bt
#0 boost::re_detail::basic_regex_parser<char, boost::regex_traits<char,
boost::cpp_regex_traits<char> > >::parse_extended (this=0xbfcff47c)
at
/usr/local/dev/boost-1.37.0/include/boost/regex/v4/basic_regex_parser.hpp:247
#1 0xb7ef6476 in boost::re_detail::basic_regex_parser<char,
boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse ()
from
/usr/local/dev/boost-1.37.0/lib/libboost_regex-gcc41-mt-1_37.so.1.37.0
#2 0xb7ef8634 in boost::basic_regex<char, boost::regex_traits<char,
boost::cpp_regex_traits<char> > >::do_assign ()
from
/usr/local/dev/boost-1.37.0/lib/libboost_regex-gcc41-mt-1_37.so.1.37.0
#3 0x0804f26b in main () at
/usr/local/dev/boost-1.37.0/include/boost/regex/v4/basic_regex.hpp:262
(gdb) q
The program is running. Exit anyway? (y or n) y
krivenok_at_develop2 18:17:42 /tmp $
>
> Here's a small example that shows the problem:
> #include <boost/algorithm/string/regex.hpp>
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> int main()
> {
> string input ("test test1 test2 test3");
> string pattern ("\\btest\\b");
>
> erase_regex (input, boost::regex (pattern));
>
> cout << input << endl; // expecting " test1 test2 test3"
> return 0;
> }
>
> Compile flags (and this is getting to the heart of the problem, I think):
> -g -m32 -malign-double -O3 -Wall -lboost_regex
>
> Put all the above together in a bag, shake it up, and you get this
> segfault:
> 0x08066beb in boost::re_detail::basic_regex_parser<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> >
> >::parse_extended (this=0xffde311c)
> at /usr/include/boost/regex/v4/basic_regex_parser.hpp:235
> 235 switch*this->m_traits.syntax_type(*m_position))
> (gdb) print m_position
> $1 = 0x0
> (gdb) bt
> #0 0x08066beb in boost::re_detail::basic_regex_parser<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> >
> >::parse_extended
> at /usr/include/boost/regex/v4/basic_regex_parser.hpp:235
> #1 0xf7f9e364 in boost ::re_detail::basic_regex_parser<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse ()
> from /usr/lib/libboost_regex.so.2
> #2 0xf7fa0eba in boost::basic_regex<char, boost::regex_traits<char,
> boost::cpp_regex_traits<char> > >::do_assign () from
> /usr/lib/libboost_regex.so.2
> #3 0x08050789 in main () at
> /usr/include/boost/regex/v4/basic_regex.hpp:254
>
> So the immediate culprit is a dereferencing-null problem.
>
> Interestingly, the problem goes away at -O, -O1, and -O2. Or -O3 but
> without -malign-double.
The same results.
>
> I was wondering if this is a known problem, and if anyone else who's
> hand is forced to compile with -malign-double has seen this problem
> and been able to work around it?
>
> --
> Andrew Troschinetz
> Applied Research Laboratories
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Sincerely yours, Dmitry V. Krivenok Orange System Company Saint-Petersburg, Russia work phone: +7 812 332-32-40 cellular phone: +7 921 576-70-91 e-mail: krivenok_at_[hidden] web: http://www.orangesystem.ru skype: krivenok_dmitry jabber: krivenok_dmitry_at_[hidden] icq: 242-526-443
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net