Mercurial > minori
comparison dep/fmt/test/fuzzing/chrono-timepoint.cc @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 20 Jun 2024 05:56:06 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
342:adb79bdde329 | 343:1faa72660932 |
---|---|
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 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; | |
15 | |
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); | |
22 | |
23 std::string message = fmt::format(format_str.get(), timepoint); | |
24 } | |
25 | |
26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
27 try { | |
28 doit<std::chrono::system_clock>(data, size); | |
29 } catch (...) { | |
30 } | |
31 return 0; | |
32 } |