Configure clang-format to use the Google style and re-format the C++ files. (#87)
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f6cb8ad --- /dev/null +++ b/.clang-format
@@ -0,0 +1 @@ +BasedOnStyle: Google
diff --git a/examples/empty_fuzz_test.cc b/examples/empty_fuzz_test.cc index ce9df2d..3c71cfd 100644 --- a/examples/empty_fuzz_test.cc +++ b/examples/empty_fuzz_test.cc
@@ -14,8 +14,8 @@ // A plain fuzz target that does nothing (just returns). -#include <cstdint> #include <cstddef> +#include <cstdint> extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0;
diff --git a/examples/fuzzed_data_provider_fuzz_test.cc b/examples/fuzzed_data_provider_fuzz_test.cc index b281dbe..6af63f2 100644 --- a/examples/fuzzed_data_provider_fuzz_test.cc +++ b/examples/fuzzed_data_provider_fuzz_test.cc
@@ -15,17 +15,18 @@ // A fuzz target that demonstrates the use of FuzzeddataProvider. #include <fuzzer/FuzzedDataProvider.h> -#include <cstdint> + #include <cstddef> +#include <cstdint> extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - FuzzedDataProvider fuzzed_data(data, size); + FuzzedDataProvider fuzzed_data(data, size); - const auto first_part_size = fuzzed_data.ConsumeIntegral<uint16_t>(); - std::vector<uint8_t> first_part = - fuzzed_data.ConsumeBytes<uint8_t>(first_part_size); - std::vector<uint8_t> second_part = + const auto first_part_size = fuzzed_data.ConsumeIntegral<uint16_t>(); + std::vector<uint8_t> first_part = + fuzzed_data.ConsumeBytes<uint8_t>(first_part_size); + std::vector<uint8_t> second_part = fuzzed_data.ConsumeRemainingBytes<uint8_t>(); - return 0; + return 0; }
diff --git a/examples/hang_fuzz_test.cc b/examples/hang_fuzz_test.cc index d2ce948..445a042 100644 --- a/examples/hang_fuzz_test.cc +++ b/examples/hang_fuzz_test.cc
@@ -14,12 +14,12 @@ // A fuzz target that hangs. -#include <cstdint> #include <cstddef> +#include <cstdint> extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { while (true) { - continue; + continue; } return 0;
diff --git a/examples/input_buffer_overflow_fuzz_test.cc b/examples/input_buffer_overflow_fuzz_test.cc index e8e81f4..f442f33 100644 --- a/examples/input_buffer_overflow_fuzz_test.cc +++ b/examples/input_buffer_overflow_fuzz_test.cc
@@ -12,15 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include <cstdio> -#include <cstdint> #include <cstddef> +#include <cstdint> +#include <cstdio> void TriggerBufferOverflow(const uint8_t *data, size_t size) { - if (size >= 3 && - data[0] == 'F' && - data[1] == 'U' && - data[2] == 'Z' && + if (size >= 3 && data[0] == 'F' && data[1] == 'U' && data[2] == 'Z' && data[3] == 'Z') { fprintf(stderr, "BUFFER OVERFLOW!\n"); }
diff --git a/examples/msan_fuzz_test.cc b/examples/msan_fuzz_test.cc index 2e17c4b..05b3d31 100644 --- a/examples/msan_fuzz_test.cc +++ b/examples/msan_fuzz_test.cc
@@ -14,11 +14,11 @@ // A fuzz target that causes an MSAN error (e.g., uninitialized variables). -#include <cstdint> #include <cstddef> +#include <cstdint> extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - int a; - if (a) ++a; - return 0; + int a; + if (a) ++a; + return 0; }
diff --git a/examples/new_buffer_overflow_fuzz_test.cc b/examples/new_buffer_overflow_fuzz_test.cc index 8f2e6b8..c702827 100644 --- a/examples/new_buffer_overflow_fuzz_test.cc +++ b/examples/new_buffer_overflow_fuzz_test.cc
@@ -12,25 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include <cstdio> -#include <cstdint> #include <cstddef> +#include <cstdint> +#include <cstdio> #include <cstring> void TriggerBufferOverflow(const uint8_t *data, size_t size) { - if (size >= 3 && - data[0] == 'F' && - data[1] == 'U' && - data[2] == 'Z' && + if (size >= 3 && data[0] == 'F' && data[1] == 'U' && data[2] == 'Z' && data[3] == 'Z') { fprintf(stderr, "BUFFER OVERFLOW!\n"); } } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - uint8_t* data_copy = new uint8_t[size]; + uint8_t *data_copy = new uint8_t[size]; memcpy(data_copy, data, size); TriggerBufferOverflow(data_copy, size); - delete []data_copy; + delete[] data_copy; return 0; }
diff --git a/examples/oom_fuzz_test.cc b/examples/oom_fuzz_test.cc index 817b8e7..7611bc8 100644 --- a/examples/oom_fuzz_test.cc +++ b/examples/oom_fuzz_test.cc
@@ -14,21 +14,21 @@ // A fuzz target that creates a memory leak and causes OOM errors. -#include <cstdint> #include <cstddef> +#include <cstdint> void LeakMemory() { - int* zombie_ptr = new int(100); - zombie_ptr[0] = 0; + int* zombie_ptr = new int(100); + zombie_ptr[0] = 0; } void TriggerOomError() { - for (size_t i = 0; i < (1 << 30); ++i) { - LeakMemory(); - } + for (size_t i = 0; i < (1 << 30); ++i) { + LeakMemory(); + } } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - TriggerOomError(); - return 0; +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + TriggerOomError(); + return 0; }
diff --git a/examples/re2_fuzz_test.cc b/examples/re2_fuzz_test.cc index 7e94590..903b2d5 100644 --- a/examples/re2_fuzz_test.cc +++ b/examples/re2_fuzz_test.cc
@@ -16,13 +16,13 @@ // See RE2's own fuzz tests for real-world examples that follow best practices, // e.g.: https://github.com/google/re2/blob/master/re2/fuzzing/re2_fuzzer.cc -#include <cstdint> #include <cstddef> +#include <cstdint> #include <string> #include "re2/re2.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - RE2 re(std::string(reinterpret_cast<const char*>(data), size), RE2::Quiet); - return 0; + RE2 re(std::string(reinterpret_cast<const char*>(data), size), RE2::Quiet); + return 0; }