Possible bug: regex, lexical_cast
Hi all
I have come across a bug associated with lexical_cast and regex (though
the culprit may well be the Visual C++ compiler). I have stripped the code
to the bare essentials. This worked OK under VC++ 8 (2005), but gives an
access violation under VC++ 9 (2008). This occurs with both boost 1.39 and
1.42.
Simplified code follows:
#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0
#include ::~basic_string While I have found several work-arounds, it would be useful to log this,
if it is a bug, in the correct place - boost? MS?
Appologies for the extended junk at the end of this email!
John
John Foster
Senior Quantitative Credit Developer
Model Development, Group Credit Portfolio & Models
National Australia Bank
Level 15, 500 Bourke St, Melbourne VIC 3000
Tel: +61 (0)3 8641 5228
Email: John.X.Foster@nab.com.au
This e-mail is sent by or on behalf of the named sender identified above.
If:
(a) you do not wish to receive any e-mail marketing material from this
person in the future, please forward the contents of this email to
unsubscribe@nab.com.au with the word "unsubscribe" in the subject box.
(b) you wish to unsubscribe from all central e-mail marketing lists used
by our business, please forward the contents of this e-mail to
unsubscribeall@nab.com.au with the message "unsubscribe from all central
e-mail marketing lists" in the subject box.
If you do not forward the contents of this e-mail with your
unsubscription then it may not be able to be implemented.
The information contained in this e-mail communication may be
confidential. You should only read, disclose, re-transmit, copy,
distribute, act in reliance on or commercialise the information if you
are authorised to do so. If you are not the intended recipient of this
e-mail communication, please immediately notify us by e-mail to
postmaster@nab.com.au, or reply by e-mail direct to the sender and then
destroy any electronic and paper copy of this message. Any views
expressed in this e-mail communication are those of the individual
sender, except where the sender specifically states them to be the views
of a member of the National Australia Bank Group of companies. Any
advice contained in this e-mail has been prepared without taking into
account your objectives, financial situation or needs. Before acting on
any advice in this e-mail, National Australia Bank Limited recommends
that you consider whether it is appropriate for your circumstances. If
this e-mail contains reference to any financial products, the National
recommends you consider the Product Disclosure Statement (PDS) or other
disclosure document before making any decisions regarding any products.
The National Australia Bank Group of companies does not represent,
warrant or guarantee that the integrity of this communication has been
maintained nor that the communication is free of errors, virus or
interference.
AMDG John.X.Foster@nab.com.au wrote:
I have come across a bug associated with lexical_cast and regex (though the culprit may well be the Visual C++ compiler). I have stripped the code to the bare essentials. This worked OK under VC++ 8 (2005), but gives an access violation under VC++ 9 (2008). This occurs with both boost 1.39 and 1.42.
Simplified code follows:
#define _SECURE_SCL 0 #define _HAS_ITERATOR_DEBUGGING 0
These #defines are probably mismatched between the regex library and your code. In Christ, Steven Watanabe
John.X.Foster@nab.com.au wrote:
I have come across a bug associated with lexical_cast and regex (though the culprit may well be the Visual C++ compiler). I have stripped the code to the bare essentials. This worked OK under VC++ 8 (2005), but gives an access violation under VC++ 9 (2008). This occurs with both boost 1.39 and 1.42.
Simplified code follows:
#define _SECURE_SCL 0 #define _HAS_ITERATOR_DEBUGGING 0
These #defines are probably mismatched between the regex library and your code.
Thanks for your suggestion, but this is not the case. All the code has been built with these flags. Please see my follow-up post - I now believe ostringstream is the problem, and I have colleagues who have experienced similar problems with that class. There is also some internet correspondence on the topic. John John Foster Senior Quantitative Credit Developer Model Development, Group Credit Portfolio & Models National Australia Bank Level 15, 500 Bourke St, Melbourne VIC 3000 Tel: +61 (0)3 8641 5228 Email: John.X.Foster@nab.com.au This e-mail is sent by or on behalf of the named sender identified above. If: (a) you do not wish to receive any e-mail marketing material from this person in the future, please forward the contents of this email to unsubscribe@nab.com.au with the word "unsubscribe" in the subject box. (b) you wish to unsubscribe from all central e-mail marketing lists used by our business, please forward the contents of this e-mail to unsubscribeall@nab.com.au with the message "unsubscribe from all central e-mail marketing lists" in the subject box. If you do not forward the contents of this e-mail with your unsubscription then it may not be able to be implemented. The information contained in this e-mail communication may be confidential. You should only read, disclose, re-transmit, copy, distribute, act in reliance on or commercialise the information if you are authorised to do so. If you are not the intended recipient of this e-mail communication, please immediately notify us by e-mail to postmaster@nab.com.au, or reply by e-mail direct to the sender and then destroy any electronic and paper copy of this message. Any views expressed in this e-mail communication are those of the individual sender, except where the sender specifically states them to be the views of a member of the National Australia Bank Group of companies. Any advice contained in this e-mail has been prepared without taking into account your objectives, financial situation or needs. Before acting on any advice in this e-mail, National Australia Bank Limited recommends that you consider whether it is appropriate for your circumstances. If this e-mail contains reference to any financial products, the National recommends you consider the Product Disclosure Statement (PDS) or other disclosure document before making any decisions regarding any products. The National Australia Bank Group of companies does not represent, warrant or guarantee that the integrity of this communication has been maintained nor that the communication is free of errors, virus or interference.
2010/4/12
Thanks for your suggestion, but this is not the case. All the code has been built with these flags. Please see my follow-up post - I now believe ostringstream is the problem, and I have colleagues who have experienced similar problems with that class. There is also some internet correspondence on the topic.
Note that your code does not use ostringstream, so your analysis is wrong. I'm 99% sure that Steven's guess is correct. Try to recall how you built boost regex library. How did you pass _SECURE_SCL 0 and _HAS_ITERATOR_DEBUGGING 0 to it? Roman Perepelitsa.
Apologies in advance for the long disclaimer at the end of this message!
Note that your code does not use ostringstream, so your analysis is wrong. I'm 99% sure that Steven's guess is correct. Try to recall how you built boost regex library. How did you pass _SECURE_SCL 0 and _HAS_ITERATOR_DEBUGGING 0 to it?
Roman Perepelitsa._______________________________________________
Roman
While you are 99% sure its a boost library build problem, I am fairly
certain it is not. The libraries were built with:
.\bjam -a --with-regex --with-thread --with-date_time --with-filesystem
--with-program_options define=_SECURE_SCL=0
define=_HAS_ITERATOR_DEBUGGING=0 define=_SCL_SECURE_NO_WARNINGS
define=_CRT_NONSTDC_NO_DEPRECATE define=_CRT_SECURE_NO_DEPRECATE
define=_SCL_SECURE_NO_DEPRECATE -d+2 > bjamout.txt
Example build output is:
file
bin.v2\libs\regex\build\msvc-9.0\debug\link-static\threading-multi\c_regex_traits.obj.rsp
"libs\regex\src\..\src\c_regex_traits.cpp"
-Fo"bin.v2\libs\regex\build\msvc-9.0\debug\link-static\threading-multi\c_regex_traits.obj"
-TP
/Z7
/Od
/Ob0
/W3
/GR
/MDd
/Zc:forScope
/Zc:wchar_t
/wd4675
/EHs
-c
-DBOOST_ALL_NO_LIB=1
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE
-D_HAS_ITERATOR_DEBUGGING=0
-D_SCL_SECURE_NO_DEPRECATE
-D_SCL_SECURE_NO_WARNINGS
-D_SECURE_SCL=0
"-I."
compile-c-c++
bin.v2\libs\regex\build\msvc-9.0\debug\link-static\threading-multi\c_regex_traits.obj
call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
x86 >nul
cl /Zm800 -nologo
@"bin.v2\libs\regex\build\msvc-9.0\debug\link-static\threading-multi\c_regex_traits.obj.rsp"
You are right, though, the posted code does not use ostringstream - sorry
for the confusion. ostringstream was used in one of the various
distillations of code in trying to locate this error. Code similar to this
is used in many places, all successfully, apart from two. One used
ostringstream.
For example, replace the string concatentation:
std::string x = "x" + boost::lexical_caststd::string(i);
with:
std::ostringstream oss;
oss << "x" << i;
std::string x = oss.str();
and the bug remains. Replace it with:
std::string x = "x";
x += (std::string)boost::lexical_caststd::string(i);
and it works perfectly. Also, using boost::format instead of ostringstream
also works fine. ostringstream was also responsible for another bug of a
similar nature - all occurring in the basic_string destructor - code
below.
I think, therefore, that the boost libraries are probably not the problem
(although in these cases both regex and lexical_cast are used); my
suggestion is that the string concatentation and ostringstream use some
common code wherein lies the possible bug.
For completeness, code was built using debug multi-threaded dll libraries:
/MDd. Under VC++ 2005 all is fine; under 2008 the problem occurs. Also,
code is fine in release mode. Here is another code distillation showing a
similar problem:
#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0
#include
AMDG John.X.Foster@nab.com.au wrote:
For completeness, code was built using debug multi-threaded dll libraries: /MDd. I think this is the problem. If I build with /MD and build Boost with runtime-debugging=off, it seems to work.
Under VC++ 2005 all is fine; under 2008 the problem occurs. Also, code is fine in release mode. Here is another code distillation showing a similar problem:
In Christ, Steven Watanabe
participants (3)
-
John.X.Foster@nab.com.au
-
Roman Perepelitsa
-
Steven Watanabe