##// END OF EJS Templates
fuzzutil: make it possible to use absl when C++17 isn't supported...
Augie Fackler -
r38192:36d55f90 default
parent child Browse files
Show More
@@ -3,6 +3,10 b' fuzzutil.o: fuzzutil.cc fuzzutil.h'
3 3 -std=c++17 \
4 4 -I../../mercurial -c -o fuzzutil.o fuzzutil.cc
5 5
6 fuzzutil-oss-fuzz.o: fuzzutil.cc fuzzutil.h
7 $$CXX $$CXXFLAGS -std=c++17 \
8 -I../../mercurial -c -o fuzzutil-oss-fuzz.o fuzzutil.cc
9
6 10 bdiff.o: ../../mercurial/bdiff.c
7 11 $$CC $$CFLAGS -fsanitize=fuzzer-no-link,address -c -o bdiff.o \
8 12 ../../mercurial/bdiff.c
@@ -15,9 +19,10 b' bdiff: bdiff.cc bdiff.o fuzzutil.o'
15 19 bdiff-oss-fuzz.o: ../../mercurial/bdiff.c
16 20 $$CC $$CFLAGS -c -o bdiff-oss-fuzz.o ../../mercurial/bdiff.c
17 21
18 bdiff_fuzzer: bdiff.cc bdiff-oss-fuzz.o fuzzutil.o
22 bdiff_fuzzer: bdiff.cc bdiff-oss-fuzz.o fuzzutil-oss-fuzz.o
19 23 $$CXX $$CXXFLAGS -std=c++17 -I../../mercurial bdiff.cc \
20 bdiff-oss-fuzz.o fuzzutil.o -lFuzzingEngine -o $$OUT/bdiff_fuzzer
24 bdiff-oss-fuzz.o fuzzutil-oss-fuzz.o -lFuzzingEngine -o \
25 $$OUT/bdiff_fuzzer
21 26
22 27 x%.o: ../../mercurial/thirdparty/xdiff/x%.c ../../mercurial/thirdparty/xdiff/*.h
23 28 $$CC -g -O1 -fsanitize=fuzzer-no-link,address -c \
@@ -34,9 +39,9 b' fuzz-x%.o: ../../mercurial/thirdparty/xd'
34 39 -o $@ \
35 40 $<
36 41
37 xdiff_fuzzer: xdiff.cc fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o fuzzutil.o
42 xdiff_fuzzer: xdiff.cc fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o fuzzutil-oss-fuzz.o
38 43 $$CXX $$CXXFLAGS -std=c++17 -I../../mercurial xdiff.cc \
39 fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o fuzzutil.o \
44 fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o fuzzutil-oss-fuzz.o \
40 45 -lFuzzingEngine -o $$OUT/xdiff_fuzzer
41 46
42 47 all: bdiff xdiff
@@ -2,10 +2,10 b''
2 2
3 3 #include <utility>
4 4
5 std::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size)
5 contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size)
6 6 {
7 7 if (!Size) {
8 return std::nullopt;
8 return contrib::nullopt;
9 9 }
10 10 // figure out a random point in [0, Size] to split our input.
11 11 size_t left_size = (Data[0] / 255.0) * (Size - 1);
@@ -2,8 +2,31 b''
2 2 #define CONTRIB_FUZZ_FUZZUTIL_H
3 3 #include <iostream>
4 4 #include <memory>
5 #include <stdint.h>
6
7 /* Try and use std::optional, but failing that assume we'll have a
8 * workable https://abseil.io/ install on the include path to get
9 * their backport of std::optional. */
10 #ifdef __has_include
11 #if __has_include(<optional>) && __cplusplus >= 201703L
5 12 #include <optional>
6 #include <stdint.h>
13 #define CONTRIB_FUZZ_HAVE_STD_OPTIONAL
14 #endif
15 #endif
16 #ifdef CONTRIB_FUZZ_HAVE_STD_OPTIONAL
17 namespace contrib
18 {
19 using std::nullopt;
20 using std::optional;
21 } /* namespace contrib */
22 #else
23 #include "third_party/absl/types/optional.h"
24 namespace contrib
25 {
26 using absl::nullopt;
27 using absl::optional;
28 } /* namespace contrib */
29 #endif
7 30
8 31 /* set DEBUG to 1 for a few debugging prints, or 2 for a lot */
9 32 #define DEBUG 0
@@ -19,6 +42,6 b' struct two_inputs {'
19 42 };
20 43
21 44 /* Split a non-zero-length input into two inputs. */
22 std::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size);
45 contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size);
23 46
24 47 #endif /* CONTRIB_FUZZ_FUZZUTIL_H */
General Comments 0
You need to be logged in to leave comments. Login now