json icon indicating copy to clipboard operation
json copied to clipboard

crash on empty ifstream

Open Chrjstoph opened this issue 9 years ago • 4 comments

if file is empty, parsing crashes.

Chrjstoph avatar Mar 18 '17 11:03 Chrjstoph

Which version are you using?

nlohmann avatar Mar 18 '17 11:03 nlohmann

the latest, (of what?)

Chrjstoph avatar Mar 18 '17 11:03 Chrjstoph

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?

nlohmann avatar Mar 18 '17 11:03 nlohmann

you are right, I was confusing it with an empty json “”.

From: Niels Lohmann Sent: Saturday, March 18, 2017 12:43 PM To: nlohmann/json Cc: Christoph ; Author Subject: Re: [nlohmann/json] crash on empty ifstream (#521)

I meant the version of the library. In the develop branch, the following program

#include <json.hpp> #include

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?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Chrjstoph avatar Mar 18 '17 12:03 Chrjstoph