/src/glaze/fuzzing/json_reflection.cpp
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstddef> |
3 | | #include <cstdint> |
4 | | #include <glaze/glaze.hpp> |
5 | | #include <vector> |
6 | | |
7 | | struct my_struct |
8 | | { |
9 | | int i = 287; |
10 | | double d = 3.14; |
11 | | std::string hello = "Hello World"; |
12 | | std::array<uint64_t, 3> arr = {1, 2, 3}; |
13 | | }; |
14 | | |
15 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) |
16 | 11.6k | { |
17 | | // use a vector with null termination instead of a std::string to avoid |
18 | | // small string optimization to hide bounds problems |
19 | 11.6k | std::vector<char> buffer{Data, Data + Size}; |
20 | | |
21 | | // non-null terminated |
22 | 11.6k | { |
23 | 11.6k | my_struct obj{}; |
24 | 11.6k | [[maybe_unused]] auto ec = |
25 | 11.6k | glz::read<glz::opts{.null_terminated = false}>(obj, std::string_view{buffer.data(), Size}); |
26 | 11.6k | } |
27 | | |
28 | | // null terminated |
29 | 11.6k | { |
30 | 11.6k | buffer.push_back('\0'); |
31 | 11.6k | [[maybe_unused]] auto s = glz::read_json<my_struct>(std::string_view{buffer.data(), Size}); |
32 | 11.6k | if (s) { |
33 | | // hooray! valid json found |
34 | 3 | } |
35 | 11.6k | } |
36 | | |
37 | 11.6k | return 0; |
38 | 11.6k | } |