Mercurial > hg
comparison contrib/fuzz/fuzzutil.h @ 38173:fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Alex Gaynor suggested we should probably copy the left and right sides
of diffs to new blocks so we can detect over-reads in the diffing
code, and I agree. Once I got into that, I realized we should do
things with C++17 idioms rather than keep using malloc() and
free(). This change is the result. I tried to split it more than this
and failed.
Everything still compiles and works in the oss-fuzz container, so I
think we can count on C++17 being available!
Differential Revision: https://phab.mercurial-scm.org/D3675
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 28 Apr 2018 22:18:50 -0400 |
parents | |
children | 36d55f90e2a3 |
comparison
equal
deleted
inserted
replaced
38172:24cc2969abae | 38173:fa0ddd5e8fff |
---|---|
1 #ifndef CONTRIB_FUZZ_FUZZUTIL_H | |
2 #define CONTRIB_FUZZ_FUZZUTIL_H | |
3 #include <iostream> | |
4 #include <memory> | |
5 #include <optional> | |
6 #include <stdint.h> | |
7 | |
8 /* set DEBUG to 1 for a few debugging prints, or 2 for a lot */ | |
9 #define DEBUG 0 | |
10 #define LOG(level) \ | |
11 if (level <= DEBUG) \ | |
12 std::cout | |
13 | |
14 struct two_inputs { | |
15 std::unique_ptr<char[]> right; | |
16 size_t right_size; | |
17 std::unique_ptr<char[]> left; | |
18 size_t left_size; | |
19 }; | |
20 | |
21 /* Split a non-zero-length input into two inputs. */ | |
22 std::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size); | |
23 | |
24 #endif /* CONTRIB_FUZZ_FUZZUTIL_H */ |