chrono-timepoint.cc 828 B

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