-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fill_line_buffer incorrectly tests m_stream for eof but not fail or bad bits #493
Comments
Which version did you try? This should be fixed in the last version. |
Clearly an old version - ended up being v2.0.5. It is fixed in the constructor on the version I just pulled - v2.1.1. Is there an issue if the stream throws fail/bad while reading the stream? For example, std::getline() can set the fail bit when it can't store an the entire buffer up to the delimiter ('\n') or it can't extract any characters from the stream - both highly unlikely scenarios but throwing it out there as a potential strange behavior which would cause an infinite loop. |
You're right - we do not check the stream once we started parsing. I shall have a look whether I can create a test case for this. |
I need a test case where this is an issue. |
@TestMonkey9000 With commit 4e49829 I added a check to make sure the stream is OK before calling |
The solution looks fine - curious why use good() and not fail()? Asking because good() checks eofbit, failbit, and badbit and eofbit is checked as the other side of the overall conditional. It seemed like since it was checked above, you would either change that check to "not good()" or the inserted check to "not fail()". From a functionality standpoint, I don't see why it would matter because there isn't an operation on the stream operation between the two points...just being pedantic. |
Also merged develop into this feature branch.
Replaced old std::invalid_argument exception by parse_error.111 to have unified exceptions in case of input stream errors.
That's a good point. I overworked this. |
If the json object is asked to parse from a stream, the stream must be valid otherwise the json object goes into an infinite loop. The current code only tests for the end of file condition which assumes the incoming stream does not have the bad or fail bits set. I think a more general approach is to test with good() rather than eof().
Should be:
This will throw an exception if the stream is not open or has another issue rather than loop.
Test code:
The text was updated successfully, but these errors were encountered: