[compiler-rt] FuzzedDataProvider: do not call memcpy on empty vector.

Summary:
Some versions of memcpy mark pointer arguments as __nonnull, that triggers UBSan
errors even when the length passed is 0.

Reviewers: manojgupta, metzman

Subscribers: dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D71031

[compiler-rt] FDP: assert that num_bytes_to_consume == 0 when size == 0.
This commit is contained in:
Max Moroz 2019-12-04 13:24:59 -08:00
parent b89ba5f939
commit a44ef027eb

View File

@ -263,6 +263,12 @@ class FuzzedDataProvider {
// which seems to be a natural choice for other implementations as well.
// To increase the odds even more, we also call |shrink_to_fit| below.
std::vector<T> result(size);
if (size == 0) {
if (num_bytes_to_consume != 0)
abort();
return result;
}
std::memcpy(result.data(), data_ptr_, num_bytes_to_consume);
Advance(num_bytes_to_consume);