Coverage Report

Created: 2025-07-11 06:48

/src/glaze/fuzzing/json_generic.cpp
Line
Count
Source
1
#include <cstddef>
2
#include <cstdint>
3
#include <glaze/glaze.hpp>
4
#include <vector>
5
6
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
7
6.47k
{
8
   // non-null terminated
9
6.47k
   {
10
6.47k
      const std::vector<char> buffer{Data, Data + Size};
11
12
6.47k
      static constexpr glz::opts opts{.null_terminated = false};
13
6.47k
      glz::json_t json{};
14
6.47k
      auto ec = glz::read<opts>(json, buffer);
15
6.47k
      if (!ec) {
16
2.37k
         [[maybe_unused]] auto s = json.size();
17
2.37k
      }
18
6.47k
   }
19
20
   // use a vector with null termination instead of a std::string to avoid
21
   // small string optimization to hide bounds problems
22
6.47k
   std::vector<char> buffer{Data, Data + Size};
23
6.47k
   buffer.push_back('\0');
24
25
   // const qualified input buffer
26
6.47k
   {
27
6.47k
      const auto& input = buffer;
28
6.47k
      glz::json_t json{};
29
6.47k
      auto ec = glz::read_json(json, input);
30
6.47k
      if (!ec) {
31
2.35k
         [[maybe_unused]] auto s = json.size();
32
2.35k
      }
33
6.47k
   }
34
35
   // non-const input buffer
36
6.47k
   {
37
6.47k
      glz::json_t json{};
38
6.47k
      auto ec = glz::read_json(json, buffer);
39
6.47k
      if (!ec) {
40
2.31k
         [[maybe_unused]] auto s = json.size();
41
2.31k
      }
42
6.47k
   }
43
44
6.47k
   return 0;
45
6.47k
}