Skip to content

Commit

Permalink
parser::sax_parse_internal: Avoid integer conversion warning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
t-b committed Aug 30, 2019
1 parent b125e29 commit e035c9a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/nlohmann/detail/input/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cmath> // isfinite
#include <cstdint> // uint8_t
#include <functional> // function
#include <limits> // numeric_limits
#include <string> // string
#include <utility> // move
#include <vector> // vector
Expand Down Expand Up @@ -185,7 +186,7 @@ class parser
{
case token_type::begin_object:
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
if (JSON_HEDLEY_UNLIKELY(not sax->start_object((std::numeric_limits<std::size_t>::max)())))
{
return false;
}
Expand Down

0 comments on commit e035c9a

Please sign in to comment.