Skip to content

Possible fix for #4485 #4487

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

Merged
merged 28 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
17bd783
Possible fix for #4485
jordan-hoang Nov 6, 2024
62bc8f8
quick cleanup
jordan-hoang Nov 6, 2024
8386c26
Fix compile issues
jordan-hoang Nov 6, 2024
ae4d67d
moved tests around, changed exceptions, removed a possibly unneeded i…
jordan-hoang Nov 9, 2024
530e063
add back include <memory> for testing something
jordan-hoang Nov 9, 2024
f99b05a
Ninja doesn't like not having a \n, at end of file, adding it back
jordan-hoang Nov 9, 2024
3c58f91
Merge branch 'nlohmann:develop' into fix-#4485
jordan-hoang Nov 9, 2024
d3c98ae
Merge branch 'develop' into fix-#4485
jordan-hoang Nov 15, 2024
2b85d07
Merge branch 'develop' into fix-#4485
jordan-hoang Nov 16, 2024
b6344fe
Merge branch 'develop' into fix-#4485
jordan-hoang Nov 17, 2024
557c8eb
update input_adapter file to deal with empty/null file ptr.
jordan-hoang Nov 17, 2024
fe877cc
ran make pretty
jordan-hoang Nov 18, 2024
11f5ce0
added test for inputadapter
jordan-hoang Nov 18, 2024
529d19c
ran make amalgamate
jordan-hoang Nov 18, 2024
c81514c
Update tests/src/unit-deserialization.cpp
jordan-hoang Nov 18, 2024
8f4f265
Update tests/src/unit-deserialization.cpp
jordan-hoang Nov 18, 2024
d884284
Update input adapters.hpp with new includes
jordan-hoang Nov 18, 2024
ee774a3
Merge branch 'fix-#4485' of https://github.com/jordan-hoang/json into…
jordan-hoang Nov 18, 2024
d121495
fix unabigious use of _, (there was a double declare)
jordan-hoang Nov 18, 2024
8ca7ea7
did the amalagamate
jordan-hoang Nov 19, 2024
1dfb9e7
rm duplicate includes
jordan-hoang Nov 19, 2024
0bd5c79
Merge branch 'fix-#4485' of https://github.com/jordan-hoang/json into…
jordan-hoang Nov 19, 2024
fd1f3b8
make amalgamate again
jordan-hoang Nov 19, 2024
fc89258
reorder
jordan-hoang Nov 19, 2024
e69cae3
amalgamate
jordan-hoang Nov 19, 2024
7e302f7
moved it above
jordan-hoang Nov 19, 2024
7f3c748
Merge branch 'fix-#4485' of https://github.com/jordan-hoang/json into…
jordan-hoang Nov 19, 2024
97c4eac
amalgamate
jordan-hoang Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/nlohmann/detail/input/input_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string> // string, char_traits
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
#include <utility> // pair, declval
#include <nlohmann/detail/exceptions.hpp>

#ifndef JSON_NO_IO
#include <cstdio> // FILE *
Expand Down Expand Up @@ -420,6 +421,10 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory<C
// Special cases with fast paths
inline file_input_adapter input_adapter(std::FILE* file)
{
if (file == nullptr)
{
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
}
return file_input_adapter(file);
}

Expand All @@ -446,6 +451,10 @@ template < typename CharT,
int >::type = 0 >
contiguous_bytes_input_adapter input_adapter(CharT b)
{
if (b == nullptr)
{
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
}
auto length = std::strlen(reinterpret_cast<const char*>(b));
const auto* ptr = reinterpret_cast<const char*>(b);
return input_adapter(ptr, ptr + length);
Expand Down
12 changes: 12 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6227,6 +6227,10 @@ NLOHMANN_JSON_NAMESPACE_END
#include <string> // string, char_traits
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
#include <utility> // pair, declval
// #include <nlohmann/detail/exceptions.hpp>

// #include <nlohmann/detail/macro_scope.hpp>


#ifndef JSON_NO_IO
#include <cstdio> // FILE *
Expand Down Expand Up @@ -6633,6 +6637,10 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory<C
// Special cases with fast paths
inline file_input_adapter input_adapter(std::FILE* file)
{
if (file == nullptr)
{
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
}
return file_input_adapter(file);
}

Expand All @@ -6659,6 +6667,10 @@ template < typename CharT,
int >::type = 0 >
contiguous_bytes_input_adapter input_adapter(CharT b)
{
if (b == nullptr)
{
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
}
auto length = std::strlen(reinterpret_cast<const char*>(b));
const auto* ptr = reinterpret_cast<const char*>(b);
return input_adapter(ptr, ptr + length);
Expand Down
1 change: 0 additions & 1 deletion tests/src/unit-concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ TEST_CASE("concepts")
// a, b: values of type X: json

// TABLE 96 - Container Requirements

// X::value_type must return T
CHECK((std::is_same<json::value_type, json>::value));

Expand Down
4 changes: 4 additions & 0 deletions tests/src/unit-deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ TEST_CASE("deserialization")
"start_object()", "key(one)", "number_unsigned(1)",
"end_object()", "parse_error(29)"
}));

const char* string = nullptr;
CHECK_THROWS_WITH_AS(_ = json::parse(string), "[json.exception.parse_error.101] parse error: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
CHECK_THROWS_WITH_AS(_ = json::parse(nullptr), "[json.exception.parse_error.101] parse error: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
}

SECTION("operator<<")
Expand Down
Loading