json
json copied to clipboard
Null-dereference warning in value_to
I'm using boost 1.83 and gcc13.2 and can see a gcc compiler warning about a potential null de-reference.
In function 'boost::json::result<T> boost::json::detail::value_to_impl(sequence_conversion_tag, boost::json::try_value_to_tag<T>, const boost::json::value&, const Ctx&) [with T = std::array<unsigned char, 128>; Ctx = std::tuple<allow_exceptions, no_context>]',
inlined from 'typename boost::json::result_for<T, boost::json::value>::type boost::json::try_value_to(const value&, const Context&) [with T = std::array<unsigned char, 128>; Context = std::tuple<detail::allow_exceptions, detail::no_context>]' at /usr/include/boost/json/value_to.hpp:230:33:
/usr/include/boost/json/detail/value_to.hpp:315:16: warning: potential null pointer dereference [-Wnull-dereference]
315 | *ins++ = std::move(*elem_res);
Is the check elem_res.has_error() insufficient to guarantee that no null-pointer de-reference will happen?
I couldn't reproduce it. Can you please change this snippet (https://godbolt.org/z/4az5z7eva ), so that it hits that warning?
@grisumbras I can see issue in a larger code base. Will try to re-create in a smaller context.