Coverage Report

Created: 2026-10-28 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glaze/fuzzing/json_prettify.cpp
Line
Count
Source
1
#include <cstddef>
2
#include <cstdint>
3
#include <glaze/glaze.hpp>
4
#include <string>
5
#include <vector>
6
7
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
8
44.6k
{
9
   // use a vector with null termination instead of a std::string to avoid
10
   // small string optimization to hide bounds problems
11
44.6k
   std::vector<char> buffer{Data, Data + Size};
12
13
   // non-null terminated
14
44.6k
   {
15
44.6k
      const auto& input = buffer;
16
44.6k
      [[maybe_unused]] auto beautiful = glz::prettify_json(input);
17
44.6k
   }
18
19
   // null terminated
20
44.6k
   {
21
44.6k
      buffer.push_back('\0');
22
44.6k
      const auto& input = buffer;
23
44.6k
      [[maybe_unused]] auto beautiful = glz::prettify_json(input);
24
44.6k
   }
25
26
   // The comment enabled path is a different scan: read_jsonc_comment only runs here, and it is
27
   // the scanner that has to report an unterminated comment rather than hand an empty view to a
28
   // memcpy. Fuzzed as its own input because a document rejected by the plain path may be accepted
29
   // by this one.
30
44.6k
   {
31
44.6k
      const std::vector<char> jsonc{Data, Data + Size};
32
44.6k
      [[maybe_unused]] auto beautiful = glz::prettify_jsonc(jsonc);
33
44.6k
   }
34
35
   // Only a self-terminating buffer selects the null terminated scan. A vector carrying a
36
   // trailing NUL does not: that NUL is just a byte inside the document.
37
44.6k
   {
38
44.6k
      const std::string jsonc{Data, Data + Size};
39
44.6k
      [[maybe_unused]] auto beautiful = glz::prettify_jsonc(jsonc);
40
44.6k
   }
41
42
44.6k
   return 0;
43
44.6k
}