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

crash on empty ifstream #521

Closed
Chrjstoph opened this issue Mar 18, 2017 · 4 comments
Closed

crash on empty ifstream #521

Chrjstoph opened this issue Mar 18, 2017 · 4 comments

Comments

@Chrjstoph
Copy link

if file is empty, parsing crashes.

@nlohmann
Copy link
Owner

Which version are you using?

@Chrjstoph
Copy link
Author

the latest, (of what?)

@nlohmann
Copy link
Owner

nlohmann commented Mar 18, 2017

I meant the version of the library. In the develop branch, the following program (and an empty file empty.json)

#include <json.hpp>
#include <fstream>

using json = nlohmann::json;

int main()
{
    std::ifstream f_empty("empty.json");
    json j = json::parse(f_empty);
    std::cout << j << std::endl;
}

aborts with

libc++abi.dylib: terminating with uncaught exception of type nlohmann::detail::parse_error: 
[json.exception.parse_error.101] parse error at 2: parse error - unexpected end of input

Apart from the file position (2) this seems to make sense. What did you expect?

@Chrjstoph
Copy link
Author

Chrjstoph commented Mar 18, 2017 via email

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