Coverage Report

Created: 2025-08-26 06:22

/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
7.66k
{
8
   // non-null terminated
9
7.66k
   {
10
7.66k
      const std::vector<char> buffer{Data, Data + Size};
11
12
7.66k
      static constexpr glz::opts opts{.null_terminated = false};
13
7.66k
      glz::json_t json{};
14
7.66k
      auto ec = glz::read<opts>(json, buffer);
15
7.66k
      if (!ec) {
16
2.87k
         [[maybe_unused]] auto s = json.size();
17
2.87k
      }
18
7.66k
   }
19
20
   // use a vector with null termination instead of a std::string to avoid
21
   // small string optimization to hide bounds problems
22
7.66k
   std::vector<char> buffer{Data, Data + Size};
23
7.66k
   buffer.push_back('\0');
24
25
   // const qualified input buffer
26
7.66k
   {
27
7.66k
      const auto& input = buffer;
28
7.66k
      glz::json_t json{};
29
7.66k
      auto ec = glz::read_json(json, input);
30
7.66k
      if (!ec) {
31
2.84k
         [[maybe_unused]] auto s = json.size();
32
2.84k
      }
33
7.66k
   }
34
35
   // non-const input buffer
36
7.66k
   {
37
7.66k
      glz::json_t json{};
38
7.66k
      auto ec = glz::read_json(json, buffer);
39
7.66k
      if (!ec) {
40
2.79k
         [[maybe_unused]] auto s = json.size();
41
2.79k
      }
42
7.66k
   }
43
44
7.66k
   return 0;
45
7.66k
}