Include fmt 11.0.2
[openal-soft.git] / fmt-11.0.2 / test / fuzzing / chrono-timepoint.cc
blob8a1b24d29458105db7189f3508ffebbd90eeb668
1 // Copyright (c) 2021, Paul Dreik
2 // For license information refer to format.h.
3 #include <fmt/chrono.h>
5 #include "fuzzer-common.h"
7 /*
8 * a fuzzer for the chrono timepoints formatters
9 * C is a clock (std::chrono::system_clock etc)
11 template <typename C> void doit(const uint8_t* data, size_t size) {
12 using Rep = typename C::time_point::rep;
13 constexpr auto N = sizeof(Rep);
14 if (size < N) return;
16 const auto x = assign_from_buf<Rep>(data);
17 typename C::duration dur{x};
18 typename C::time_point timepoint{dur};
19 data += N;
20 size -= N;
21 data_to_string format_str(data, size);
23 std::string message = fmt::format(format_str.get(), timepoint);
26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
27 try {
28 doit<std::chrono::system_clock>(data, size);
29 } catch (...) {
31 return 0;