/src/glaze/fuzzing/cbor_roundtrip_string.cpp
Line | Count | Source |
1 | | #include <cassert> |
2 | | #include <cstddef> |
3 | | #include <cstdint> |
4 | | #include <cstring> |
5 | | #include <glaze/cbor.hpp> |
6 | | #include <glaze/glaze.hpp> |
7 | | #include <vector> |
8 | | |
9 | | struct S |
10 | | { |
11 | | std::string value{}; |
12 | | }; |
13 | | |
14 | | void test(const uint8_t* Data, size_t Size) |
15 | 0 | { |
16 | 0 | S s{{Data, Data + Size}}; |
17 | | |
18 | | // CBOR handles arbitrary byte sequences in strings, no escaping needed |
19 | 0 | std::string buffer{}; |
20 | 0 | auto write_ec = glz::write_cbor(s, buffer); |
21 | 0 | if (write_ec) { |
22 | 0 | return; |
23 | 0 | } |
24 | 0 | auto restored = glz::read_cbor<S>(buffer); |
25 | 0 | assert(restored); |
26 | 0 | assert(restored.value().value == s.value); |
27 | 0 | } |
28 | | |
29 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) |
30 | 11.4k | { |
31 | 11.4k | test(Data, Size); |
32 | 11.4k | return 0; |
33 | 11.4k | } |