Skip to content

Commit e035c9a

Browse files
committed
parser::sax_parse_internal: Avoid integer conversion warning
Clang UBSAN complains here with /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_bvector.h:158:20: runtime error: unsigned integer overflow: 0 - 1 cannot b e represented in type 'unsigned int' #0 0x61f497 in std::_Bit_iterator_base::_M_bump_down() /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_bvector.h:158:2 0 nlohmann#1 0x61b7eb in bool nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::sax_parse_internal<nlohmann::detail::json_sa x_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> > >(nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vecto r, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_ serializer> >*) /home/firma/devel/json/include/nlohmann/detail/input/json_sax.hpp nlohmann#2 0x611f33 in nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std: :allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse(bool, nlohmann::basic_json<std::map, std::v ector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann:: adl_serializer>&) /home/firma/devel/json/include/nlohmann/detail/input/parser.hpp:116:13 nlohmann#3 0x5d0522 in nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>::parse(nlohmann::detail::input_adapter&&, std::function<bool (int, nlohmann:: detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, lon g, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse_event_t, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic _string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>&)>, bool)/ home/firma/devel/json/include/nlohmann/json.hpp:6160:41 nlohmann#4 0x5af340 in _DOCTEST_ANON_FUNC_84() /home/firma/devel/json/test/src/unit-msgpack.cpp:1321:19 nlohmann#5 0x657d5e in doctest::Context::run() /home/firma/devel/json/test/thirdparty/doctest/doctest.h:5938:21 nlohmann#6 0x65c700 in main /home/firma/devel/json/test/thirdparty/doctest/doctest.h:6016:71 nlohmann#7 0x7f17952e32e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) nlohmann#8 0x453f29 in _start (/home/firma/devel/json/build/test/test-msgpack+0x453f29) so to make it happy we use the "official" way of denoting the maximum value of a size_t instead of the shortcut by casting.
1 parent b125e29 commit e035c9a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: include/nlohmann/detail/input/parser.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cmath> // isfinite
55
#include <cstdint> // uint8_t
66
#include <functional> // function
7+
#include <limits> // numeric_limits
78
#include <string> // string
89
#include <utility> // move
910
#include <vector> // vector
@@ -185,7 +186,7 @@ class parser
185186
{
186187
case token_type::begin_object:
187188
{
188-
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
189+
if (JSON_HEDLEY_UNLIKELY(not sax->start_object((std::numeric_limits<std::size_t>::max)())))
189190
{
190191
return false;
191192
}

0 commit comments

Comments
 (0)