diff --git a/include/nlohmann/detail/view/string_ref.hpp b/include/nlohmann/detail/view/string_ref.hpp index bb9605bf6..d401500ec 100644 --- a/include/nlohmann/detail/view/string_ref.hpp +++ b/include/nlohmann/detail/view/string_ref.hpp @@ -40,6 +40,8 @@ class string_ref using const_iterator = const char*; string_ref() noexcept = default; + // s must be null-terminated, as for std::string_view(const char*) + // flawfinder: ignore string_ref(const char* s) : m_data(s), m_size(std::strlen(s)) {} // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) string_ref(const char* s, std::size_t n) noexcept : m_data(s), m_size(n) {} template diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index 5ced50c55..882101336 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -870,6 +870,7 @@ class basic_json_document /// parse into this document, reusing its memory template + // flawfinder: ignore (a member function, not POSIX read()) void read(InputType&& input, const bool allow_exceptions = true, const bool ignore_comments = false, @@ -1036,6 +1037,8 @@ class basic_json_document return; } const char* cs = reinterpret_cast(s); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) + // C strings are null-terminated, as for json::parse(const char*) + // flawfinder: ignore build(cs, std::strlen(cs), ae, c, tc, false, true); } diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index c658e3352..4427e73fc 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -3451,6 +3451,8 @@ class string_ref using const_iterator = const char*; string_ref() noexcept = default; + // s must be null-terminated, as for std::string_view(const char*) + // flawfinder: ignore string_ref(const char* s) : m_data(s), m_size(std::strlen(s)) {} // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) string_ref(const char* s, std::size_t n) noexcept : m_data(s), m_size(n) {} template @@ -4446,6 +4448,7 @@ class basic_json_document /// parse into this document, reusing its memory template + // flawfinder: ignore (a member function, not POSIX read()) void read(InputType&& input, const bool allow_exceptions = true, const bool ignore_comments = false, @@ -4612,6 +4615,8 @@ class basic_json_document return; } const char* cs = reinterpret_cast(s); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) + // C strings are null-terminated, as for json::parse(const char*) + // flawfinder: ignore build(cs, std::strlen(cs), ae, c, tc, false, true); }