Good morning all,
I used regex library which is shipped with boost 1.30 in my project. But
I found in the case I list below, the regex_match() will crash. Is there
a pitfall in it?
===================== CODE LIST BEGIN =========================
#include "stdafx.h"
#include
I used regex library which is shipped with boost 1.30 in my project. But I found in the case I list below, the regex_match() will crash. Is there a pitfall in it?
Yes, it will through an exception if the complexity of the attempted match grows too high - the alternative is to just keep trying indefinately. You need to: 1) catch the exception (it's a runtime_error). 2) analyse your regex to reduce ambiguity during matching so that the matcher spends less time "thrashing" trying to find a match. John.
===================== CODE LIST BEGIN ========================= #include "stdafx.h" #include
#include using namespace boost; void do_regex_match(const string& s) { USES_CONVERSION;
CString _c1,_c2; _c1 = "\\_gl_glcf]a:(D_N~yOA_gg_aeN_o/>jm_gf'0(m_--\\6L_gi_AE_gd5<&0A~_E'_Y-'-,uO7 _so_glTc G_gl_C,_o/*6hC=@_u"; // Failed _c2 = "\\_gl_glcf]a:(D_N~yOA_gg_aeN_o/jm_gf'0(m_--\\6L_gi_AE_gd5<&0A~_E'_Y-'-,uO7_ so_glTc G_gl_C,_o/*6hC=@_u"; // Passed
wstring ws1(L""),ws2(L""); ws1=A2W(_c1); ws2=A2W(_c2);
wstring wsMatchString(L""); wsMatchString=A2W(".*(要)?.*天气.*");
boost::wregex e(wsMatchString/*,boost::regbase::normal|boost::regbase::icase*/); boost::regex_match(ws2,e);// Pass boost::regex_match(ws1,e);// Crash } ======================== CODE LIST END ========================= As you can see in the code, if any change is made to _c1, the test will pass or it will crash. I will list my compiler and system information below.
Compiler: Microsoft Visual C++ 6.0 Professionall with SP5 OS: Microsoft Windows 2000 Professional with SP3 RAM: 512M CPU: PIII 700
Any help will be appreciated.
Phipps Xue
Software Engineer, MCP/MCSD Email: xuejm@sina.com
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
participants (2)
-
John Maddock
-
Phipps Xue