Mercurial > hg
diff contrib/fuzz/xdiff.cc @ 43614:78df32a8b6f4
fuzz: migrate xdiff fuzzer to use FuzzedDataProvider
Differential Revision: https://phab.mercurial-scm.org/D7369
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 11 Nov 2019 16:37:18 -0500 |
parents | 2e60a77b7058 |
children | 51a99e09c54b |
line wrap: on
line diff
--- a/contrib/fuzz/xdiff.cc Mon Nov 11 14:48:30 2019 -0500 +++ b/contrib/fuzz/xdiff.cc Mon Nov 11 16:37:18 2019 -0500 @@ -10,7 +10,7 @@ #include <inttypes.h> #include <stdlib.h> -#include "fuzzutil.h" +#include <fuzzer/FuzzedDataProvider.h> extern "C" { @@ -27,17 +27,15 @@ if (Size > 100000) { return 0; } - auto maybe_inputs = SplitInputs(Data, Size); - if (!maybe_inputs) { - return 0; - } - auto inputs = std::move(maybe_inputs.value()); + FuzzedDataProvider provider(Data, Size); + std::string left = provider.ConsumeRandomLengthString(Size); + std::string right = provider.ConsumeRemainingBytesAsString(); mmfile_t a, b; - a.ptr = inputs.left.get(); - a.size = inputs.left_size; - b.ptr = inputs.right.get(); - b.size = inputs.right_size; + a.ptr = (char *)left.c_str(); + a.size = left.size(); + b.ptr = (char *)right.c_str(); + b.size = right.size(); xpparam_t xpp = { XDF_INDENT_HEURISTIC, /* flags */ };