fuzz_textflow.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //License: Boost 1.0
  2. //By Paul Dreik 2020
  3. #include <catch2/internal/catch_textflow.hpp>
  4. #include "NullOStream.h"
  5. #include <string>
  6. #include <string_view>
  7. template<class Callback>
  8. void split(const char *Data, size_t Size, Callback callback) {
  9. using namespace std::literals;
  10. constexpr auto sep="\n~~~\n"sv;
  11. std::string_view remainder(Data,Size);
  12. for (;;) {
  13. auto pos=remainder.find(sep);
  14. if(pos==std::string_view::npos) {
  15. //not found. use the remainder and exit
  16. callback(remainder);
  17. return;
  18. } else {
  19. //found. invoke callback on the first part, then proceed with the rest.
  20. callback(remainder.substr(0,pos));
  21. remainder=remainder.substr(pos+sep.size());
  22. }
  23. }
  24. }
  25. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  26. Catch::TextFlow::Columns columns;
  27. // break the input on separator
  28. split((const char*)Data,Size,[&](std::string_view word) {
  29. columns+=Catch::TextFlow::Column(std::string(word));
  30. });
  31. NullOStream nul;
  32. nul << columns;
  33. return 0;
  34. }