Boost C++ Libraries: Ticket #6405: Assertion exception thrown when using boost::regex_match https://svn.boost.org/trac10/ticket/6405 <p> When attempting to do a regex match using the following code: </p> <pre class="wiki"> bool isValidEmailAddr(const std::string &amp; addr) { boost::regex reg("((^|@)[[:alnum:]!#$%&amp;'*+/=?^_`{|}~-]+(.[[:alnum:]!#$%&amp;'*+/=?^_`{|}~-]+)*){2}$"); return boost::regex_match(addr, reg); } </pre><p> on a linux box with boost 1.48, gcc version 4.4.6 i get the following error: </p> <p> /usr/include/boost/smart_ptr/shared_ptr.hpp:418: typename boost::detail::shared_ptr_traits&lt;T&gt;::reference boost::shared_ptr&lt;T&gt;::operator*() const [with T = boost::regex_traits_wrapper&lt;boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;]: Assertion `px != 0' failed. Aborted </p> <p> Moving my code to my mac, compiling with boost 1.48, gcc 4.7 all seems to work fine. </p> <p> Additionally, if I try to print the regex on the linux box I get: </p> <p> terminate called after throwing an instance of 'std::logic_error' </p> <blockquote> <p> what(): basic_string::_S_construct NULL not valid </p> </blockquote> <p> I'm going to try to upgrade my linux box to gcc 4.7, but I would like to understand what the problem is. </p> <p> Thanks much. </p> <p> 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. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6405 Trac 1.4.3 anonymous Fri, 20 Jan 2012 18:22:33 GMT <link>https://svn.boost.org/trac10/ticket/6405#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:1</guid> <description> <p> 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. </p> <p> Also is this 32 or 64-bit Linux? </p> <p> 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). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Piotr</dc:creator> <pubDate>Thu, 29 Mar 2012 09:04:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6405#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:2</guid> <description> <p> 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. </p> <p> Regards, </p> <p> Piotr </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 29 Mar 2012 09:05:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6405#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:3</guid> <description> <p> 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. </p> <p> Regards, </p> <p> Piotr </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 07 Jul 2012 18:37:49 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6405#comment:4 https://svn.boost.org/trac10/ticket/6405#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> Closed pending further information. </p> Ticket anonymous Fri, 09 Aug 2013 14:45:02 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/6405#comment:5 https://svn.boost.org/trac10/ticket/6405#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">worksforme</span> </li> </ul> <p> I am afraid, we have the same issue on <strong>Win32</strong> platform (MS Visual Stodio 2008 VC++, boost v.<strong>1.48</strong>): </p> <pre class="wiki">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); } </pre><p> It works fine in <strong>Debug</strong>, but throws an exeption: </p> <pre class="wiki">Unhandled exception at 0x77a415de in tester.exe: 0xC0000005: Access violation writing location 0x00000008. </pre><p> in <strong>Release</strong> mode. We have tried to play with different prohject settings, but that did not help. </p> <p> Here is an example of input string which definetly brings an exeption: "<code>p@mail.ru</code>". </p> <p> -- </p> <p> Nikita A, </p> <p> with best ragards, and thanks a lot for your ansrewers in advance! </p> Ticket anonymous Fri, 09 Aug 2013 16:07:31 GMT <link>https://svn.boost.org/trac10/ticket/6405#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:6</guid> <description> <p> Your example works for me with current Boost (1.54) in both debug and release mode and VC10. </p> <p> 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. </p> <p> Many thanks, John Maddock. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 12 Aug 2013 06:02:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6405#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:7</guid> <description> <p> Thenk you very much, John! </p> <p> 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. </p> <p> 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. </p> <p> Nikita A. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 12 Aug 2013 10:22:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6405#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:8</guid> <description> <p> I have downloaded and installed <strong>boost v.1.54</strong>. </p> <p> Unfortunately, nothing has changed - the problem persists. </p> <p> We have prepared for you a very short example, illustrating the problem (see in Attachments). </p> <p> We use <strong>MS Visual Studio 2008 SP1</strong>. The program alwais fails in <strong>Win32 Release</strong> mode, in this line: </p> <pre class="wiki">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); &lt;&lt;== FAILS RIGHT HERE! } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 12 Aug 2013 10:23:18 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6405 https://svn.boost.org/trac10/ticket/6405 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">tester.zip</span> </li> </ul> Ticket anonymous Mon, 12 Aug 2013 13:31:53 GMT <link>https://svn.boost.org/trac10/ticket/6405#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:9</guid> <description> <p> P.S. When we removed the NDEBUG preprocessor directive, we got such assertion: </p> <pre class="wiki">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. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 12 Aug 2013 13:39:31 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/6405#comment:10 https://svn.boost.org/trac10/ticket/6405#comment:10 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.48.0</span> → <span class="trac-field-new">Boost 1.54.0</span> </li> </ul> <p> <strong>P.P.S.</strong> Please never mind <strong>1.48</strong> paths references, because this folder actually contains <strong>1.54</strong> boost installation. We did not rename it not to have to modify the main project settings. </p> Ticket anonymous Mon, 12 Aug 2013 17:25:06 GMT <link>https://svn.boost.org/trac10/ticket/6405#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:11</guid> <description> <p> I'm still unable to reproduce with either VC9 or VC10. </p> <p> Can you, with your test project: </p> <ul><li>Add the preprocessor define BOOST_ALL_NO_LIB. </li><li>Add the source files boost-path/libs/regex/src/*.cpp directly to your project. </li></ul><p> And then try again? </p> <p> Only thing I can think of at this point is that there is some strange binary-mismatch between the .lib files and your project. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 13 Aug 2013 06:35:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6405#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:12</guid> <description> <p> 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. </p> <p> Here is the command line we used to compile boost on our side: </p> <pre class="wiki">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 </pre><p> <em>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.</em> </p> <p> Can you please provide us with only one file - <strong>libboost_filesystem-vc90-mt-s-1_48.lib</strong>, built on your side? We'd like to try our project to link with it here. </p> <p> Also may be you have some recommendations for us about the command line above? </p> <p> Thanks for your assistance! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 13 Aug 2013 10:59:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6405#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6405#comment:13</guid> <description> <p> John, I think we have just found the reason and solved the problem! </p> <p> As you could see in the post above, the command line for building boost contains the directive: <strong>define=_SECURE_SCL=0</strong>. But nor our testing project, nor the project we've met this problem firstly, did not contain it. </p> <p> So simply adding the line "_SECURE_SCL=0" to <strong>C/C++ - Preprocessor - Preprocessor definitions</strong> in project properties stopped throwing exceptions. </p> <p> <em>I think this article may be usefull for anyone browsing Internet and trying to find a solution of a similar trouble: <code>preshing.com/20110807/the-cost-of-_secure_scl</code></em> </p> <p> <strong>THANK YOU VERY MUCH AGAIN FOR ALL YOUR HELP! </strong> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 13 Aug 2013 11:46:42 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6405#comment:14 https://svn.boost.org/trac10/ticket/6405#comment:14 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> Glad you got it solved, as you have discovered changing _SECURE_SCL changes the ABI of the std lib. </p> <p> 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. </p> Ticket