Mercurial > public > mercurial-scm > hg
annotate contrib/fuzz/xdiff.cc @ 39878:3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Parsing and writing of revision text metadata is likely identical
across storage backends. Let's move the code out of revlog so we
don't need to import the revlog module in order to use it.
Differential Revision: https://phab.mercurial-scm.org/D4754
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 24 Sep 2018 14:31:31 -0700 |
parents | fa0ddd5e8fff |
children | 2e60a77b7058 |
rev | line source |
---|---|
36679 | 1 /* |
2 * xdiff.cc - fuzzer harness for thirdparty/xdiff | |
3 * | |
4 * Copyright 2018, Google Inc. | |
5 * | |
6 * This software may be used and distributed according to the terms of | |
7 * the GNU General Public License, incorporated herein by reference. | |
8 */ | |
9 #include "thirdparty/xdiff/xdiff.h" | |
10 #include <inttypes.h> | |
11 #include <stdlib.h> | |
12 | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
13 #include "fuzzutil.h" |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
14 |
36679 | 15 extern "C" { |
16 | |
17 int hunk_consumer(long a1, long a2, long b1, long b2, void *priv) | |
18 { | |
19 // TODO: probably also test returning -1 from this when things break? | |
20 return 0; | |
21 } | |
22 | |
23 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | |
24 { | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
25 auto maybe_inputs = SplitInputs(Data, Size); |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
26 if (!maybe_inputs) { |
36679 | 27 return 0; |
28 } | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
29 auto inputs = std::move(maybe_inputs.value()); |
36679 | 30 mmfile_t a, b; |
31 | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
32 a.ptr = inputs.left.get(); |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
33 a.size = inputs.left_size; |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
34 b.ptr = inputs.right.get(); |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
35 b.size = inputs.right_size; |
36679 | 36 xpparam_t xpp = { |
37 XDF_INDENT_HEURISTIC, /* flags */ | |
38 }; | |
39 xdemitconf_t xecfg = { | |
40 XDL_EMIT_BDIFFHUNK, /* flags */ | |
41 hunk_consumer, /* hunk_consume_func */ | |
42 }; | |
43 xdemitcb_t ecb = { | |
44 NULL, /* priv */ | |
45 }; | |
46 xdl_diff(&a, &b, &xpp, &xecfg, &ecb); | |
47 return 0; // Non-zero return values are reserved for future use. | |
48 } | |
49 | |
50 #ifdef HG_FUZZER_INCLUDE_MAIN | |
51 int main(int argc, char **argv) | |
52 { | |
53 const char data[] = "asdf"; | |
54 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4); | |
55 } | |
56 #endif | |
57 | |
58 } // extern "C" |