C++ assertion crash when using boost regex lib

578 Views Asked by At

I just installed the boost lib and visual studio on my new laptop.

I'm getting the following error while trying to run my code:

Assertion failed: r != 0, file libs\regex\build\..\src\w32_regex_traits.cpp, line 125

The error occurs when running in debug 32bit, but works when using release instead of debug. This is my snippet:

#include <iostream>
#include <boost/regex.hpp>
int main()
{
     boost::regex("hello word", boost::regex::icase);
}

I tried to re-install VS2019 and the boost lib, but the problem persists.

Any ideas what could be the cause of the error?

3

There are 3 best solutions below

0
sehe On

The assert is here:

#ifndef BOOST_NO_ANSI_APIS
   int r = ::LCMapStringA(this->m_locale, LCMAP_LOWERCASE, char_map, 1 << CHAR_BIT, this->m_lower_map, 1 << CHAR_BIT);
   BOOST_ASSERT(r != 0);
#else

It looks like LCMapStringA function fails.

This function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:

  • ERROR_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.
  • ERROR_INVALID_FLAGS. The values supplied for flags were not valid.
  • ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.

I do not think these conditions are ignorable. They might lead to Undefined Behavior. So, perhaps you can use the debugger to get the value of GetLastError at the point when it failed to get more information.

Depending on the kind of failure you

  • fix your system config (perhaps locale support is missing?)
  • fix your input (perhaps your input contains invalid encoding)
  • report a bug to the boost devs (in case there is a buffer sizing issue that is not a documented limitation)
0
cdo-dev On

After changing the regional format from English(XXXX) region to English (United State) issue was resolved

0
sakra On

I got the same assertion crash under Windows and was able to fix it by defining BOOST_REGEX_NO_W32.