Coverage Report

Created: 2025-11-18 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fmt/test/fuzzing/chrono-timepoint.cc
Line
Count
Source
1
// Copyright (c) 2021, Paul Dreik
2
// For license information refer to format.h.
3
#include <fmt/chrono.h>
4
5
#include "fuzzer-common.h"
6
7
/*
8
 * a fuzzer for the chrono timepoints formatters
9
 * C is a clock (std::chrono::system_clock etc)
10
 */
11
4.10k
template <typename C> void doit(const uint8_t* data, size_t size) {
12
4.10k
  using Rep = typename C::time_point::rep;
13
4.10k
  constexpr auto N = sizeof(Rep);
14
4.10k
  if (size < N) return;
15
16
4.10k
  const auto x = assign_from_buf<Rep>(data);
17
4.10k
  typename C::duration dur{x};
18
4.10k
  typename C::time_point timepoint{dur};
19
4.10k
  data += N;
20
4.10k
  size -= N;
21
4.10k
  data_to_string format_str(data, size);
22
23
4.10k
  std::string message = fmt::format(format_str.get(), timepoint);
24
4.10k
}
25
26
4.10k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
27
4.10k
  try {
28
4.10k
    doit<std::chrono::system_clock>(data, size);
29
4.10k
  } catch (...) {
30
3.87k
  }
31
4.10k
  return 0;
32
4.10k
}