Skip to content
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

Null-dereference warning in value_to #994

Open
infn-ke opened this issue Mar 21, 2024 · 2 comments
Open

Null-dereference warning in value_to #994

infn-ke opened this issue Mar 21, 2024 · 2 comments

Comments

@infn-ke
Copy link

infn-ke commented Mar 21, 2024

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?

@grisumbras
Copy link
Member

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

@infn-ke
Copy link
Author

infn-ke commented Mar 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants