Boost regexp (Perl) throws initialization error for [^\0x21-\0xfe]
If my code contains the following regexp, const boost::tregex non_printables(__T("[^\0x21-\0x7E]+")); The program throws the following dialog box on initialization. The stack trace follows. Please forward to someone who cares :-) The following regexp, works as expected const boost::tregex non_printables(__T("[^!-~]+")); --Brad ntdll.dll!_KiFastSystemCallRet@0() ntdll.dll!_ZwWaitForMultipleObjects@20() + 0xc bytes kernel32.dll!_UnhandledExceptionFilter@4() + 0x84b bytes mscoree.dll!_abort() + 0xeb bytes mscoree.dll!terminate() + 0x2a bytes mscoree.dll!__CxxUnhandledExceptionFilter() + 0x39 bytes kernel32.dll!_UnhandledExceptionFilter@4() + 0x149 bytes
msvcr80d.dll!_XcptFilter(unsigned long xcptnum=3765269347,
::fail(boost::regex_constants::error_type error_code=error_paren, int
_EXCEPTION_POINTERS * pxcptinfoptrs=0x0007da0c) Line 237 + 0xa bytes
C
msvcr80d.dll!__CppXcptFilter(unsigned long
xcptnum=3765269347, _EXCEPTION_POINTERS * pxcptinfoptrs=0x0007da0c)
Line 147 + 0xd bytes C
mathdlld.dll!__DllMainCRTStartup(void *
hDllHandle=0x01010000, unsigned long dwReason=1, void *
lpreserved=0x00000000) Line 517 + 0x17 bytes C
msvcr80d.dll!@_EH4_CallFilterFunc@8() + 0x12 bytes Asm
mathdlld.dll!_except_handler4(_EXCEPTION_RECORD *
ExceptionRecord=0x0007db20, _EXCEPTION_REGISTRATION_RECORD *
EstablisherFrame=0x0007e15c, _CONTEXT * ContextRecord=0x0007db40, void *
DispatcherContext=0x0007daf4) + 0x22 bytes C
ntdll.dll!ExecuteHandler2@20() + 0x26 bytes
ntdll.dll!ExecuteHandler@20() + 0x24 bytes
ntdll.dll!_KiUserExceptionDispatcher@8() + 0xe bytes
kernel32.dll!_RaiseException@16() + 0x52 bytes
msvcr80d.dll!_CxxThrowException(void *
pExceptionObject=0x0007deb0, const _s__ThrowInfo *
pThrowInfo=0x00b98b08) Line 166 C++
boost_regex-vc80-mt-gd-1_33_1.dll!boost::throw_exception
::parse(const wchar_t * p1=0x01735a34, const wchar_t * p2=0x01735a38, unsigned int flags=0) Line 137 C++
boost_regex-vc80-mt-gd-1_33_1.dll!boost::re_detail::basic_regex_implemen
tation
::basic_regex
> >(const wchar_t * p=0x01735a34, unsigned int f=0) Line 209 C++
mathdlld.dll!`dynamic initializer for 'non_printables''() Line 65 + 0x15 bytes C++ msvcr80d.dll!_initterm(void (void)* * pfbegin=0x01701520, void (void)* * pfend=0x01702e5c) Line 855 C mathdlld.dll!_CRT_INIT(void * hDllHandle=0x01010000, unsigned long dwReason=1, void * lpreserved=0x00000000) Line 313 + 0xf bytes C mathdlld.dll!__DllMainCRTStartup(void * hDllHandle=0x01010000, unsigned long dwReason=1, void * lpreserved=0x00000000) Line 489 + 0x11 bytes C mathdlld.dll!_DllMainCRTStartup(void * hDllHandle=0x01010000, unsigned long dwReason=1, void * lpreserved=0x00000000) Line 459 + 0x11 bytes C ntdll.dll!_LdrpCallInitRoutine@16() + 0x14 bytes ntdll.dll!_LdrpRunInitializeRoutines@4() + 0x1c7 bytes ntdll.dll!_LdrpLoadDll@24() - 0x1b1 bytes ntdll.dll!_LdrLoadDll@16() + 0x110 bytes kernel32.dll!_LoadLibraryExW@12() + 0xc8 bytes regsvr32.exe!_wWinMain@16() + 0x741 bytes regsvr32.exe!_wWinMainCRTStartup() + 0x198 bytes kernel32.dll!_BaseProcessStart@4() + 0x23 bytes
Brad Barber wrote:
If my code contains the following regexp,
const boost::tregex non_printables(__T("[^\0x21-\0x7E]+"));
Don't forget that your pattern is scanned first by the C++ compiler. In this case, this means that \0x21 is never seen by the RegExp engine; instead, it sees a NUL character (ASCII 0) followed by "x21". NUL is not valid in any pattern and thus an exception is thrown. Use double backslashes to get a backslash through to the engine. Sebastian Redl
If my code contains the following regexp,
const boost::tregex non_printables(__T("[^\0x21-\0x7E]+"));
Don't forget that your pattern is scanned first by the C++ compiler. In this case, this means that \0x21 is never seen by the RegExp engine; instead, it sees a NUL character (ASCII 0) followed by "x21". NUL is not valid in any pattern and thus an exception is thrown. Use double backslashes to get a backslash through to the engine.
Quite right, and just to add to that: it's very helpful if you add a try...catch handler in main so that unhandled exceptions don't crash the application. Or to put it another way, error handling is a "good thing" :-) John.
participants (3)
-
Brad Barber
-
John Maddock
-
Sebastian Redl