json icon indicating copy to clipboard operation
json copied to clipboard

Null-dereference warning in value_to

Open infn-ke opened this issue 2 years ago • 2 comments

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?

infn-ke avatar Mar 21 '24 21:03 infn-ke

I couldn't reproduce it. Can you please change this snippet (https://godbolt.org/z/4az5z7eva ), so that it hits that warning?

grisumbras avatar Mar 22 '24 04:03 grisumbras

@grisumbras I can see issue in a larger code base. Will try to re-create in a smaller context.

infn-ke avatar Mar 27 '24 08:03 infn-ke