From a667365d0e0f3eb0bc6d6f2cfee5e128a6574aee Mon Sep 17 00:00:00 2001 From: Paul Dreik Date: Sun, 9 Jun 2019 19:38:06 +0200 Subject: [PATCH] clang format --- test/fuzzing/chrono_duration.cpp | 91 ++++++++++++++++---------------- test/fuzzing/named_arg.cpp | 32 +++++------ 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/test/fuzzing/chrono_duration.cpp b/test/fuzzing/chrono_duration.cpp index 6a51a43ac565..d858146b2c8c 100644 --- a/test/fuzzing/chrono_duration.cpp +++ b/test/fuzzing/chrono_duration.cpp @@ -1,23 +1,23 @@ // Copyright (c) 2019, Paul Dreik // License: see LICENSE.rst in the fmt root directory +#include #include #include #include #include #include #include -#include template void invoke_inner(fmt::string_view formatstring, const Item item) { const std::chrono::duration value(item); try { - // Don't switch these two dynamically, - // there is already a large combinatoric explosion - // of type and ratio, causing afl to suffer and the corpus - // getting enormous. Occasionally, flip this switch and - // try manually. + // Don't switch these two dynamically, + // there is already a large combinatoric explosion + // of type and ratio, causing afl to suffer and the corpus + // getting enormous. Occasionally, flip this switch and + // try manually. #if 0 std::string message = fmt::format(formatstring, value); #else @@ -31,74 +31,75 @@ void invoke_inner(fmt::string_view formatstring, const Item item) { // Item is the underlying type for duration (int, long etc) template void invoke_outer(const uint8_t* Data, std::size_t Size, const int scaling) { - //always use a fixed location of the data, so different cases will - //cooperate better. the same bit pattern, interpreted as another type, - //is likely interesting. - constexpr auto Nfixed=std::max(sizeof(long double),sizeof(std::intmax_t)); + // always use a fixed location of the data, so different cases will + // cooperate better. the same bit pattern, interpreted as another type, + // is likely interesting. + constexpr auto Nfixed = std::max(sizeof(long double), sizeof(std::intmax_t)); constexpr auto N = sizeof(Item); - static_assert(N<=Nfixed, "fixed size is too small"); + static_assert(N <= Nfixed, "fixed size is too small"); if (Size <= Nfixed + 1) { return; } - static_assert(std::is_trivially_copyable::value, "Item must be blittable"); + static_assert(std::is_trivially_copyable::value, + "Item must be blittable"); Item item{}; std::memcpy(&item, Data, N); - //fast forward + // fast forward Data += Nfixed; Size -= Nfixed; // Data is already allocated separately in libFuzzer so reading past // the end will most likely be detected anyway - const auto formatstring=fmt::string_view((const char*)Data, Size); + const auto formatstring = fmt::string_view((const char*)Data, Size); // doit_impl(buf.data(),item); // doit_impl(buf.data(),item); switch (scaling) { case 1: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 2: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 3: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 4: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 5: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 6: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 7: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 8: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 9: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 10: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 11: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 12: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 13: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 14: - invoke_inner(formatstring, item); - break; + invoke_inner(formatstring, item); + break; case 15: - invoke_inner(formatstring, item); + invoke_inner(formatstring, item); } // doit_impl(buf.data(),item); // doit_impl(buf.data(),item); @@ -111,8 +112,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { const auto representation = Data[0]; const auto scaling = Data[1]; - Data+=2; - Size-=2; + Data += 2; + Size -= 2; switch (representation) { case 1: diff --git a/test/fuzzing/named_arg.cpp b/test/fuzzing/named_arg.cpp index 1c9f7afe2e12..0cbcd66d3a57 100644 --- a/test/fuzzing/named_arg.cpp +++ b/test/fuzzing/named_arg.cpp @@ -29,15 +29,15 @@ void invoke_fmt(const uint8_t* Data, std::size_t Size, int argsize) { return; } - //allocating buffers separately is slower, but increases chances - //of detecting memory errors + // allocating buffers separately is slower, but increases chances + // of detecting memory errors #define SEPARATE_ALLOCATION 1 #if SEPARATE_ALLOCATION std::vector argnamebuffer(argsize); std::memcpy(argnamebuffer.data(), Data, argsize); - auto argname=fmt::string_view(argnamebuffer.data(),argsize); - #else - auto argname=fmt::string_view((const char*)Data,argsize); + auto argname = fmt::string_view(argnamebuffer.data(), argsize); +#else + auto argname = fmt::string_view((const char*)Data, argsize); #endif Data += argsize; Size -= argsize; @@ -46,16 +46,14 @@ void invoke_fmt(const uint8_t* Data, std::size_t Size, int argsize) { // allocates as tight as possible, making it easier to catch buffer overruns. std::vector fmtstringbuffer(Size); std::memcpy(fmtstringbuffer.data(), Data, Size); - auto fmtstring=fmt::string_view(fmtstringbuffer.data(),Size); + auto fmtstring = fmt::string_view(fmtstringbuffer.data(), Size); #else - auto fmtstring=fmt::string_view((const char*)Data,Size); + auto fmtstring = fmt::string_view((const char*)Data, Size); #endif - std::string message = - fmt::format(fmtstring, fmt::arg(argname, item1)); + std::string message = fmt::format(fmtstring, fmt::arg(argname, item1)); #undef SEPARATE_ALLOCATION } - // for dynamic dispatching to an explicit instantiation template void invoke(int index, Callback callback) { switch (index) { @@ -63,21 +61,21 @@ template void invoke(int index, Callback callback) { callback(bool{}); break; case 1: - callback(char{}); + callback(char{}); break; case 11: - using sc=signed char; + using sc = signed char; callback(sc{}); break; case 21: - using uc=unsigned char; + using uc = unsigned char; callback(uc{}); break; case 2: callback(short{}); break; case 22: - using us=unsigned short; + using us = unsigned short; callback(us{}); break; case 3: @@ -90,7 +88,7 @@ template void invoke(int index, Callback callback) { callback(long{}); break; case 14: - using ul=unsigned long; + using ul = unsigned long; callback(ul{}); break; case 5: @@ -117,7 +115,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { Data++; Size--; - auto outerfcn = [=](auto param1) { invoke_fmt(Data, Size, second); }; + auto outerfcn = [=](auto param1) { + invoke_fmt(Data, Size, second); + }; try { invoke(first, outerfcn);