提交 4bb41d06 编写于 作者: N Niels Lohmann

🐛 parsing erroneous files yields an exception (#366)

上级 ed611119
......@@ -7597,6 +7597,12 @@ class basic_json
explicit lexer(std::istream& s)
: m_stream(&s), m_line_buffer()
{
// immediately abort if stream is erroneous
if (s.fail())
{
throw std::invalid_argument("stream error: " + std::string(strerror(errno)));
}
// fill buffer
fill_line_buffer();
......
......@@ -7597,6 +7597,12 @@ class basic_json
explicit lexer(std::istream& s)
: m_stream(&s), m_line_buffer()
{
// immediately abort if stream is erroneous
if (s.fail())
{
throw std::invalid_argument("stream error: " + std::string(strerror(errno)));
}
// fill buffer
fill_line_buffer();
......
......@@ -495,4 +495,10 @@ TEST_CASE("regression tests")
json j = json::parse("22e2222");
CHECK(j == json());
}
SECTION("issue #366 - json::parse on failed stream gets stuck")
{
std::ifstream f("file_not_found.json");
CHECK_THROWS_AS(json::parse(f), std::invalid_argument);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册