crash on empty ifstream
if file is empty, parsing crashes.
Which version are you using?
the latest, (of what?)
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?
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.