Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldreik committed Apr 27, 2019
1 parent 793d97b commit 8b934b3
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 199 deletions.
91 changes: 39 additions & 52 deletions fuzzing/named_arg.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// Copyright (c) 2019, Paul Dreik
// License: see LICENSE.rst in the fmt root directory

#include <cstdint>
#include <fmt/core.h>
#include <fmt/chrono.h>
#include <fmt/core.h>
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <type_traits>
#include <vector>

template<typename Item1>
void
doit(const uint8_t* Data, std::size_t Size, int argsize)
{

template <typename Item1>
void doit(const uint8_t* Data, std::size_t Size, int argsize) {
const auto N1 = sizeof(Item1);
if (Size <= N1) {
return;
}
Item1 item1{};
if /*constexpr*/ (std::is_same<Item1, bool>::value) {
if /*constexpr*/ (std::is_same<Item1, bool>::value) {
item1 = !!Data[0];
} else {
std::memcpy(&item1, Data, N1);
Expand All @@ -41,12 +38,10 @@ doit(const uint8_t* Data, std::size_t Size, int argsize)
std::vector<char> buf(Size + 1);
std::memcpy(buf.data(), Data, Size);
std::string message =
fmt::format(buf.data(), fmt::arg(argname.data(), item1));
fmt::format(buf.data(), fmt::arg(argname.data(), item1));
}

void
doit_time(const uint8_t* Data, std::size_t Size)
{
void doit_time(const uint8_t* Data, std::size_t Size) {
using Item = std::time_t;
const auto N = sizeof(Item);
if (Size <= N) {
Expand All @@ -66,43 +61,37 @@ doit_time(const uint8_t* Data, std::size_t Size)
}

// for dynamic dispatching to an explicit instantiation
template<typename Callback>
void
invoke(int index, Callback callback)
{
template <typename Callback> void invoke(int index, Callback callback) {
switch (index) {
case 0:
callback(bool{});
break;
case 1:
callback(char{});
break;
case 2:
callback(short{});
break;
case 3:
callback(int{});
break;
case 4:
callback(long{});
break;
case 5:
callback(float{});
break;
case 6:
callback(double{});
break;
case 7:
using LD = long double;
callback(LD{});
break;
case 0:
callback(bool{});
break;
case 1:
callback(char{});
break;
case 2:
callback(short{});
break;
case 3:
callback(int{});
break;
case 4:
callback(long{});
break;
case 5:
callback(float{});
break;
case 6:
callback(double{});
break;
case 7:
using LD = long double;
callback(LD{});
break;
}
}

extern "C" int
LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)
{

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) {
if (Size <= 3) {
return 0;
}
Expand All @@ -123,13 +112,11 @@ LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)
}

#ifdef IMPLEMENT_MAIN
#include <cassert>
#include <fstream>
#include <sstream>
#include <vector>
int
main(int argc, char* argv[])
{
# include <cassert>
# include <fstream>
# include <sstream>
# include <vector>
int main(int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) {
std::ifstream in(argv[i]);
assert(in);
Expand Down
86 changes: 38 additions & 48 deletions fuzzing/one_arg.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
// Copyright (c) 2019, Paul Dreik
// License: see LICENSE.rst in the fmt root directory

#include <cstdint>
#include <fmt/core.h>
#include <cstdint>
#include <stdexcept>
#include <type_traits>
#include <vector>

#include <fmt/chrono.h>

template<typename Item>
void
doit(const uint8_t* Data, std::size_t Size)
{
template <typename Item> void doit(const uint8_t* Data, std::size_t Size) {
const auto N = sizeof(Item);
if (Size <= N) {
return;
Expand All @@ -32,9 +29,7 @@ doit(const uint8_t* Data, std::size_t Size)
std::string message = fmt::format(buf.data(), item);
}

void
doit_time(const uint8_t* Data, std::size_t Size)
{
void doit_time(const uint8_t* Data, std::size_t Size) {
using Item = std::time_t;
const auto N = sizeof(Item);
if (Size <= N) {
Expand All @@ -54,10 +49,7 @@ doit_time(const uint8_t* Data, std::size_t Size)
}
}

extern "C" int
LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)
{

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) {
if (Size <= 3) {
return 0;
}
Expand All @@ -68,49 +60,47 @@ LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)

try {
switch (first) {
case 0:
doit<bool>(Data, Size);
break;
case 1:
doit<char>(Data, Size);
break;
case 2:
doit<short>(Data, Size);
break;
case 3:
doit<int>(Data, Size);
break;
case 4:
doit<long>(Data, Size);
break;
case 5:
doit<float>(Data, Size);
break;
case 6:
doit<double>(Data, Size);
break;
case 7:
doit<long double>(Data, Size);
break;
case 8:
doit_time(Data, Size);
break;
default:
break;
case 0:
doit<bool>(Data, Size);
break;
case 1:
doit<char>(Data, Size);
break;
case 2:
doit<short>(Data, Size);
break;
case 3:
doit<int>(Data, Size);
break;
case 4:
doit<long>(Data, Size);
break;
case 5:
doit<float>(Data, Size);
break;
case 6:
doit<double>(Data, Size);
break;
case 7:
doit<long double>(Data, Size);
break;
case 8:
doit_time(Data, Size);
break;
default:
break;
}
} catch (std::exception& e) {
}
return 0;
}

#ifdef IMPLEMENT_MAIN
#include <cassert>
#include <fstream>
#include <sstream>
#include <vector>
int
main(int argc, char* argv[])
{
# include <cassert>
# include <fstream>
# include <sstream>
# include <vector>
int main(int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) {
std::ifstream in(argv[i]);
assert(in);
Expand Down
86 changes: 38 additions & 48 deletions fuzzing/sprintf.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
// Copyright (c) 2019, Paul Dreik
// License: see LICENSE.rst in the fmt root directory
#include <cstdint>
#include <fmt/chrono.h>
#include <fmt/core.h>
#include <fmt/printf.h>
#include <fmt/chrono.h>
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <type_traits>
#include <vector>

template<typename Item1, typename Item2>
void
doit(const uint8_t* Data, std::size_t Size)
{
template <typename Item1, typename Item2>
void doit(const uint8_t* Data, std::size_t Size) {
const auto N1 = sizeof(Item1);
const auto N2 = sizeof(Item2);
if (Size <= N1 + N2) {
return;
}
Item1 item1{};
if /*constexpr*/ (std::is_same<Item1, bool>::value) {
if /*constexpr*/ (std::is_same<Item1, bool>::value) {
item1 = !!Data[0];
} else {
std::memcpy(&item1, Data, N1);
Expand All @@ -28,7 +26,7 @@ doit(const uint8_t* Data, std::size_t Size)
Size -= N1;

Item2 item2{};
if /*constexpr*/ (std::is_same<Item2, bool>::value) {
if /*constexpr*/ (std::is_same<Item2, bool>::value) {
item2 = !!Data[0];
} else {
std::memcpy(&item2, Data, N2);
Expand All @@ -44,43 +42,37 @@ doit(const uint8_t* Data, std::size_t Size)
}

// for dynamic dispatching to an explicit instantiation
template<typename Callback>
void
invoke(int index, Callback callback)
{
template <typename Callback> void invoke(int index, Callback callback) {
switch (index) {
case 0:
callback(bool{});
break;
case 1:
callback(char{});
break;
case 2:
callback(short{});
break;
case 3:
callback(int{});
break;
case 4:
callback(long{});
break;
case 5:
callback(float{});
break;
case 6:
callback(double{});
break;
case 7:
using LD = long double;
callback(LD{});
break;
case 0:
callback(bool{});
break;
case 1:
callback(char{});
break;
case 2:
callback(short{});
break;
case 3:
callback(int{});
break;
case 4:
callback(long{});
break;
case 5:
callback(float{});
break;
case 6:
callback(double{});
break;
case 7:
using LD = long double;
callback(LD{});
break;
}
}

extern "C" int
LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)
{

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) {
if (Size <= 3) {
return 0;
}
Expand Down Expand Up @@ -108,13 +100,11 @@ LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)
}

#ifdef IMPLEMENT_MAIN
#include <cassert>
#include <fstream>
#include <sstream>
#include <vector>
int
main(int argc, char* argv[])
{
# include <cassert>
# include <fstream>
# include <sstream>
# include <vector>
int main(int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) {
std::ifstream in(argv[i]);
assert(in);
Expand Down
Loading

0 comments on commit 8b934b3

Please sign in to comment.