// Copyright (c) 2024 Mikhail Khachayants (mkhachaiants@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/json // #include #if !defined(BOOST_DESCRIBE_CXX14) #include BOOST_PRAGMA_MESSAGE( "This example requires C++14" ) int main() {} #else #include #include #include #include #ifndef BOOST_NO_CXX17_HDR_OPTIONAL # include # define IF_CXX17_HDR_OPTIONAL(...) __VA_ARGS__ #else # define IF_CXX17_HDR_OPTIONAL(...) #endif // BOOST_NO_CXX17_HDR_OPTIONAL using namespace boost::json; struct Object { bool b; float f; double d; std::int64_t i64; std::uint64_t u64; std::string s; std::vector v1; std::vector v2; std::vector v3; std::array a1; std::array a2; std::array a3; std::map m1; std::map m2; std::map m3; std::tuple t1; std::tuple, std::array, std::nullptr_t> t2; std::tuple, std::vector> t3; boost::variant2::variant v; #ifndef BOOST_NO_CXX17_HDR_OPTIONAL std::optional ob; std::optional oi; std::optional ou; std::optional od; std::optional os; #endif // BOOST_NO_CXX17_HDR_OPTIONAL }; BOOST_DESCRIBE_STRUCT(Object, (), (b, i64, u64, f, d, s, v1, v2, v3, a1, a2, a3, m1, m2, m3, t1, t2, t3, v, IF_CXX17_HDR_OPTIONAL(ob, oi, ou, od, os))) bool fuzz_direct_parse(string_view sv) { Object object; boost::system::error_code ec; parse_into(object, sv, ec); return !ec; } extern "C" int LLVMFuzzerTestOneInput( const uint8_t* data, size_t size) { try { string_view sv{reinterpret_cast< const char*>(data), size}; fuzz_direct_parse(sv); } catch(...) { } return 0; } #endif // !defined(BOOST_DESCRIBE_CXX14)