Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json::parse on failed stream gets stuck #366

Closed
popizdeh opened this issue Nov 23, 2016 · 4 comments
Closed

json::parse on failed stream gets stuck #366

popizdeh opened this issue Nov 23, 2016 · 4 comments

Comments

@popizdeh
Copy link

popizdeh commented Nov 23, 2016

Creating a file stream for file that doesn't exist results in stream object whose fail() method returns true. json::parse never returns when called on such a stream. Adding a check for m_stream.fail() (in addition to eof()) in fill_line_buffer seems to do the trick, invalid_argument exception gets thrown. Not sure if this is the right fix, it might also make sense checking that stream isn't 'bad' (not sure what causes this to happen as bad() for missing file stream returns false).

@nlohmann
Copy link
Owner

Thanks for reporting. I encountered the bug before, but never bothered to fix it... Commit 4bb41d0 adds a check in the lexer's constructor to immediately abort if the passed stream is fail()ed.

@nlohmann nlohmann added this to the Release 2.0.8 milestone Nov 23, 2016
@nlohmann
Copy link
Owner

@popizdeh Does this fix the issue?

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Nov 24, 2016
@popizdeh
Copy link
Author

Haven't had the chance to try and won't be able in some time. I did have a look at your fix (and test) and it looks like it'll fix the issue so I'll close the bug. Thanks for the quick response.

@nlohmann nlohmann removed the state: please discuss please discuss the issue or vote for your favorite option label Nov 25, 2016
@nlohmann
Copy link
Owner

Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants