##// END OF EJS Templates
fuzz: fix use of undeclared function memcpy()
Yuya Nishihara -
r38234:a1c0873a default
parent child Browse files
Show More
@@ -1,26 +1,27 b''
1 #include "fuzzutil.h"
1 #include "fuzzutil.h"
2
2
3 #include <cstring>
3 #include <utility>
4 #include <utility>
4
5
5 contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size)
6 contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size)
6 {
7 {
7 if (!Size) {
8 if (!Size) {
8 return contrib::nullopt;
9 return contrib::nullopt;
9 }
10 }
10 // figure out a random point in [0, Size] to split our input.
11 // figure out a random point in [0, Size] to split our input.
11 size_t left_size = (Data[0] / 255.0) * (Size - 1);
12 size_t left_size = (Data[0] / 255.0) * (Size - 1);
12
13
13 // Copy inputs to new allocations so if bdiff over-reads
14 // Copy inputs to new allocations so if bdiff over-reads
14 // AddressSanitizer can detect it.
15 // AddressSanitizer can detect it.
15 std::unique_ptr<char[]> left(new char[left_size]);
16 std::unique_ptr<char[]> left(new char[left_size]);
16 memcpy(left.get(), Data + 1, left_size);
17 std::memcpy(left.get(), Data + 1, left_size);
17 // right starts at the next byte after left ends
18 // right starts at the next byte after left ends
18 size_t right_size = Size - (left_size + 1);
19 size_t right_size = Size - (left_size + 1);
19 std::unique_ptr<char[]> right(new char[right_size]);
20 std::unique_ptr<char[]> right(new char[right_size]);
20 memcpy(right.get(), Data + 1 + left_size, right_size);
21 std::memcpy(right.get(), Data + 1 + left_size, right_size);
21 LOG(2) << "inputs are " << left_size << " and " << right_size
22 LOG(2) << "inputs are " << left_size << " and " << right_size
22 << " bytes" << std::endl;
23 << " bytes" << std::endl;
23 two_inputs result = {std::move(right), right_size, std::move(left),
24 two_inputs result = {std::move(right), right_size, std::move(left),
24 left_size};
25 left_size};
25 return result;
26 return result;
26 }
27 }
General Comments 0
You need to be logged in to leave comments. Login now