comparison contrib/fuzz/fuzzutil.cc @ 38232:a1c0873a9990

fuzz: fix use of undeclared function memcpy()
author Yuya Nishihara <yuya@tcha.org>
date Sun, 03 Jun 2018 13:12:32 +0900
parents 36d55f90e2a3
children
comparison
equal deleted inserted replaced
38231:4dd3b6c68f96 38232:a1c0873a9990
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) {
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;