Repository navigation
Description
I'm experiencing a runtime abort with MSVC 2015 14.0.24720.00 Update 1 while attempting to read a file using the ">>" operator. The file was written by this library as well, using the "<<" operator.
A dialog appears with "abort() has been called", hitting retry drops me into the debugger.
I don't think there's anything very novel about my code:
json document; std::ifstream in; in.exceptions(std::ifstream::failbit | std::ifstream::badbit); in.open(filepath); in >> document;
For now the work around is to read the file into a string, then call parse()
here's the data I'm trying to read
file_in_question.json.txt
Stack trace
> bumped.exe!__GSHandlerCheck_EH(_EXCEPTION_RECORD * ExceptionRecord, void * EstablisherFrame, _CONTEXT * ContextRecord, _DISPATCHER_CONTEXT * DispatcherContext) Line 101 C
...bunch of msvc runtime...
bumped.exe!std::getline<char,std::char_traits<char>,std::allocator<char> >(std::basic_istream<char,std::char_traits<char> > && _Istr, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Str, const char _Delim) Line 120 C++
bumped.exe!std::getline<char,std::char_traits<char>,std::allocator<char> >(std::basic_istream<char,std::char_traits<char> > & _Istr, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Str) Line 162 C++
bumped.exe!nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,double,std::allocator>::lexer::yyfill() Line 7636 C++
bumped.exe!nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,double,std::allocator>::lexer::scan() Line 6877 C++
bumped.exe!nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,double,std::allocator>::parser::get_token() Line 8118 C++
bumped.exe!nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,double,std::allocator>::parser::parse_internal(bool keep) Line 7961 C++
bumped.exe!nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,double,std::allocator>::parser::parse() Line 7889 C++
bumped.exe!nlohmann::operator>>(std::basic_istream<char,std::char_traits<char> > & i, nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,double,std::allocator> & j) Line 5287 C++
Activity
kevin-- commentedon Mar 15, 2016
by the way, working from the v1.1.0 tag
nlohmann commentedon Mar 20, 2016
Hi @kevin--, sorry about the bug. As I do not work with Windows/MSVC myself, it's difficult do dig deeper into the issue.
kevin-- commentedon Mar 20, 2016
I'll take a crack at it this week when I get a chance
duncanwerner commentedon Mar 21, 2016
According to http://en.cppreference.com/w/cpp/string/basic_string/getline
If no characters were extracted for whatever reason (not even the discarded delimiter), getline sets failbit and returns.
it seems like there's always a call to yyfill at the end of the stream, so if you are masking failbit, it will throw an exception. As to why you're getting an abort(), perhaps you're using the wrong exception model?
kevin-- commentedon Mar 21, 2016
@duncanwerner good call. If I do not set the exception mask, then I do not get the abort. Still want to look at this, because my work around of reading into the string then parsing still works. Maybe that method does not use getline.
nlohmann commentedon Mar 21, 2016
@duncanwerner Thanks for this note. I see if I can "force" this behavior on a system where I can debug.
kevin-- commentedon Mar 30, 2016
There are two points of failure, both related to calling
std::getlinestd::getline(2nd line of theexplicit lexer(std::istream* s) noexceptconstructor).std::getlinegets no content at the end of the file inyyfillAs I have discovered, the reason for the abort is because of the use of the
noexceptspecifier on all of the parser and related methods.Per the spec ( http://en.cppreference.com/w/cpp/language/noexcept_spec ) runtimes must invoke
std::terminateif an exception is being thrown through such a method. So therefore MSVC is actually acting correctly (for once).The take away here, that I didn't really think of, is that setting
failbitis inappropriate in most cases. Having read the documentation more thoroughly, it seems thisfailbitis more likely to give false-positives.I have opened a pull request which adds a note to the documentation to this effect.
Merge pull request #227 from kevin--/kevin--/noexcept_documentation
nlohmann commentedon Mar 30, 2016
I merged #227.
@kevin--, is the issue fixed for you?
kevin-- commentedon Mar 30, 2016
Yes. There was no real bug, just a clash between
failbit,getlinereading 0 chars, andnoexcept. Though I expect you should be able to reproduce this in other compilers.