Skip to content

Coverity Scan reports an UNCAUGHT_EXCEPT issue #1400

@nlohmann

Description

@nlohmann
  • What is the issue you have?

Coverity Scan reports an UNCAUGHT_EXCEPT issue.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

No. Instead here is the report:

** CID 184857:    (UNCAUGHT_EXCEPT)
/single_include/nlohmann/json.hpp: 1709 in nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<const nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>::operator !=(const nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<const nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>&) const()
/single_include/nlohmann/json.hpp: 1709 in nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>::operator !=(const nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>&) const()


________________________________________________________________________________________________________
*** CID 184857:    (UNCAUGHT_EXCEPT)
/single_include/nlohmann/json.hpp: 1709 in nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<const nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>::operator !=(const nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<const nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>&) const()
1703         bool operator==(const iteration_proxy_value& o) const noexcept
1704         {
1705             return anchor == o.anchor;
1706         }
1707     
1708         /// inequality operator (needed for range-based for)
   CID 184857:    (UNCAUGHT_EXCEPT)
   An exception of type "nlohmann::detail::invalid_iterator" is thrown but the throw list "throw()" doesn't allow it to be thrown. This will cause a call to unexpected() which usually calls terminate().
1709         bool operator!=(const iteration_proxy_value& o) const noexcept
1710         {
1711             return anchor != o.anchor;
1712         }
1713     
1714         /// return key of the iterator
/single_include/nlohmann/json.hpp: 1709 in nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>::operator !=(const nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>>>&) const()
1703         bool operator==(const iteration_proxy_value& o) const noexcept
1704         {
1705             return anchor == o.anchor;
1706         }
1707     
1708         /// inequality operator (needed for range-based for)
   CID 184857:    (UNCAUGHT_EXCEPT)
   An exception of type "nlohmann::detail::invalid_iterator" is thrown but the throw list "throw()" doesn't allow it to be thrown. This will cause a call to unexpected() which usually calls terminate().
1709         bool operator!=(const iteration_proxy_value& o) const noexcept
1710         {
1711             return anchor != o.anchor;
1712         }
1713     
1714         /// return key of the iterator
  • What is the expected behavior?

No reported issue.

  • And what is the actual behavior instead?

Reported issue.

N/A

  • Did you use a released version of the library or the version from the develop branch?

develop/ 3.5.0 release.

N/A


The problem is that the iteration_proxy_value class's comparison operators are marked noexcept. They are implemented by the underlying iterator class's comparison operators which may throw json::invalid_iterator when iterators of different JSON values are compared. Coverity Scan warns that if such an exception is thrown, the program would terminate.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions