Opened 11 years ago

Closed 9 years ago

#6405 closed Bugs (worksforme)

Assertion exception thrown when using boost::regex_match

Reported by: ses44@… Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

When attempting to do a regex match using the following code:

      bool isValidEmailAddr(const std::string & addr)
      {
        boost::regex reg("((^|@)[[:alnum:]!#$%&'*+/=?^_`{|}~-]+(.[[:alnum:]!#$%&'*+/=?^_`{|}~-]+)*){2}$");

        return boost::regex_match(addr, reg);
      }

on a linux box with boost 1.48, gcc version 4.4.6 i get the following error:

/usr/include/boost/smart_ptr/shared_ptr.hpp:418: typename boost::detail::shared_ptr_traits<T>::reference boost::shared_ptr<T>::operator*() const [with T = boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > >]: Assertion `px != 0' failed. Aborted

Moving my code to my mac, compiling with boost 1.48, gcc 4.7 all seems to work fine.

Additionally, if I try to print the regex on the linux box I get:

terminate called after throwing an instance of 'std::logic_error'

what(): basic_string::_S_construct NULL not valid

I'm going to try to upgrade my linux box to gcc 4.7, but I would like to understand what the problem is.

Thanks much.

BTW - I noticed a bug report that indicates this may happen in multi-threaded environments due to some allocation rules, but this is a very simple single threaded test.

Attachments (1)

tester.zip (2.4 KB ) - added by anonymous 9 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 by anonymous, 11 years ago

Can you please provide a complete self-contained test case, as the code executed depends upon the text being matched, and not just the regular expression.

Also is this 32 or 64-bit Linux?

There is an existing bug though that means that accessing the regex as a string doesn't work (will be fixed in the next release).

comment:2 by Piotr, 11 years ago

Hi, I had the same problem and it was caused by incorect boost instalation. I was including boost 1.48 files and linking against boost_regex from 1.40.

Regards,

Piotr

comment:3 by anonymous, 11 years ago

Hi, I had the same problem and it was caused by incorect boost instalation. I was including boost 1.48 files and linking against boost_regex from 1.40.

Regards,

Piotr

comment:4 by John Maddock, 10 years ago

Resolution: worksforme
Status: newclosed

Closed pending further information.

comment:5 by anonymous, 9 years ago

Resolution: worksforme
Status: closedreopened

I am afraid, we have the same issue on Win32 platform (MS Visual Stodio 2008 VC++, boost v.1.48):

bool isEmailAddressValid(const char* str)
{
  if (str == NULL)
  {
    return false;
  }

  static const boost::regex e("^[-a-zA-Z0-9_!#$`*+/=?^{}|.]+@([a-zA-Z0-9][-a-zA-Z0-9]+\\.)+[a-zA-Z]{2,4}$");
  return boost::regex_match(str, e);
}

It works fine in Debug, but throws an exeption:

Unhandled exception at 0x77a415de in tester.exe: 0xC0000005: Access violation writing location 0x00000008.

in Release mode. We have tried to play with different prohject settings, but that did not help.

Here is an example of input string which definetly brings an exeption: "p@mail.ru".

--

Nikita A,

with best ragards, and thanks a lot for your ansrewers in advance!

comment:6 by anonymous, 9 years ago

Your example works for me with current Boost (1.54) in both debug and release mode and VC10.

Can you please try updating you Boost version, and if that doesn't fix things, please post a complete self-contained example that illustrates the problem.

Many thanks, John Maddock.

comment:7 by anonymous, 9 years ago

Thenk you very much, John!

We'll consider today the ability to update to boost 1.54, although since our project is quite big, with many developers involved, this could meet some resistance, and may take a some time.

Anyway I could have a local expirience with v.1.54 to find out if that helps. I'll let you know about the results.

Nikita A.

comment:8 by anonymous, 9 years ago

I have downloaded and installed boost v.1.54.

Unfortunately, nothing has changed - the problem persists.

We have prepared for you a very short example, illustrating the problem (see in Attachments).

We use MS Visual Studio 2008 SP1. The program alwais fails in Win32 Release mode, in this line:

int main(int argc, char* argv[], char* envp[])
{
    static const boost::regex e("^[-a-zA-Z0-9_!#$`*+/=?^{}|.]+@([a-zA-Z0-9][-a-zA-Z0-9]+\\.)+[a-zA-Z]{2,4}$");
    return boost::regex_match("p@mail.ru", e); <<== FAILS RIGHT HERE!
}

by anonymous, 9 years ago

Attachment: tester.zip added

comment:9 by anonymous, 9 years ago

P.S. When we removed the NDEBUG preprocessor directive, we got such assertion:

Assertion failed: px != 0, file C:\Program Files (x86)\Microsoft Visual Studio 9
.0\VC\k_include\boost_1_48_0\boost/smart_ptr/shared_ptr.hpp, line 418

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

comment:10 by anonymous, 9 years ago

Version: Boost 1.48.0Boost 1.54.0

P.P.S. Please never mind 1.48 paths references, because this folder actually contains 1.54 boost installation. We did not rename it not to have to modify the main project settings.

comment:11 by anonymous, 9 years ago

I'm still unable to reproduce with either VC9 or VC10.

Can you, with your test project:

  • Add the preprocessor define BOOST_ALL_NO_LIB.
  • Add the source files boost-path/libs/regex/src/*.cpp directly to your project.

And then try again?

Only thing I can think of at this point is that there is some strange binary-mismatch between the .lib files and your project.

comment:12 by anonymous, 9 years ago

Yes, you are right - when I added BOOST_ALL_NO_LIB and included ../regex/*.cpp directly to the project, the problem dissolved. That means we really meet some binary-mismatch.

Here is the command line we used to compile boost on our side:

start bjam -a --build-type=complete --without-mpi --without-python target-os=windows toolset=msvc-9.0 define=_SECURE_SCL=0 architecture=x86 cxxflags=/Zp1 install

Nitice /Zp1 - it's here because whole our project uses such alignment. And yet, we have tried to build our testing project and boost without it - it did not help.

Can you please provide us with only one file - libboost_filesystem-vc90-mt-s-1_48.lib, built on your side? We'd like to try our project to link with it here.

Also may be you have some recommendations for us about the command line above?

Thanks for your assistance!

comment:13 by anonymous, 9 years ago

John, I think we have just found the reason and solved the problem!

As you could see in the post above, the command line for building boost contains the directive: define=_SECURE_SCL=0. But nor our testing project, nor the project we've met this problem firstly, did not contain it.

So simply adding the line "_SECURE_SCL=0" to C/C++ - Preprocessor - Preprocessor definitions in project properties stopped throwing exceptions.

I think this article may be usefull for anyone browsing Internet and trying to find a solution of a similar trouble: preshing.com/20110807/the-cost-of-_secure_scl

THANK YOU VERY MUCH AGAIN FOR ALL YOUR HELP!

comment:14 by John Maddock, 9 years ago

Resolution: worksforme
Status: reopenedclosed

Glad you got it solved, as you have discovered changing _SECURE_SCL changes the ABI of the std lib.

Please note that there's nothing special about the build scripts for these libraries - they're "just a bunch of source files", so you could build all of libs/regex/src/*.cpp into your own static lib in the IDE, then define BOOST_ALL_NO_LIB to disable auto-linking and add a reference to your static lib instead. Same with filesystem and whatever else you use.

Note: See TracTickets for help on using tickets.