Bug 47724 - [C++0x] Regex string anchors cause segfault
Summary: [C++0x] Regex string anchors cause segfault
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-13 22:51 UTC by Richard Eames
Modified: 2023-07-20 10:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-02-14 00:00:37


Attachments
Test case (255 bytes, text/x-c++src)
2011-02-13 22:51 UTC, Richard Eames
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Eames 2011-02-13 22:51:35 UTC
Created attachment 23329 [details]
Test case

Using the regex anchors "^" or "$" cause a segfault.


$ /usr/lib/gcc-snapshot/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/lib/gcc-snapshot/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 20101004-0ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs --enable-languages=c,ada,c++,fortran,objc,obj-c++ --prefix=/usr/lib/gcc-snapshot --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --disable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --with-plugin-ld=ld.gold --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.0 20101004 (experimental) [trunk revision 164952] (Ubuntu 20101004-0ubuntu1)
Comment 1 Paolo Carlini 2011-02-13 23:36:10 UTC
Note, regex is work in progress, I don't know if this is supposed to work or not. Let's ask Jon...
Comment 2 Jonathan Wakely 2011-02-14 00:00:37 UTC
I think that code's meant to support some basic operations, so the fact it crashes is definitely a bug.  We access an empty std::stack in _Compiler::_M_alternative, I'll see if I can fix it.
Comment 3 Paolo Carlini 2011-02-14 00:11:06 UTC
Thanks Jon.
Comment 4 Jonathan Wakely 2011-02-14 20:45:57 UTC
mine
Comment 5 Jonathan Wakely 2011-02-17 01:47:25 UTC
Author: redi
Date: Thu Feb 17 01:47:21 2011
New Revision: 170236

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170236
Log:
2011-02-17  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/47724
	* include/bits/regex_compiler.h (_Scanner::_M_advance): Do not treat
	line anchors as metacharacters.
	* testsuite/28_regex/basic_regex/ctors/47724.cc: New.


Added:
    trunk/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/47724.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/regex_compiler.h
Comment 6 Jonathan Wakely 2011-02-17 01:55:05 UTC
I've checked in a change which prevents the crash, but only by treating line anchors as non-metacharacters.  Unfortunately our regex implementation is incomplete, but this is better than crashing
Comment 7 Jonathan Wakely 2011-02-17 01:56:07 UTC
... so fixed