Fix seed data range calculations
Also removes assert if size == 0, since that case is now gracefully handled. BUG=chromium:1252351 Change-Id: I2c5d52a9373f34f377fda9f1689cca6096bc5e63 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/64920 Auto-Submit: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Ryan Harrison <rharrison@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
5e6d4577fd
commit
594e010cfb
|
@ -104,7 +104,6 @@ bool RandomGenerator::GetWeightedBool(uint32_t percentage) {
|
|||
|
||||
uint64_t RandomGenerator::CalculateSeed(const uint8_t* data, size_t size) {
|
||||
assert(data != nullptr && "|data| must be !nullptr");
|
||||
assert(size > 0 && "|size| must be > 0");
|
||||
|
||||
// Number of bytes we want to skip at the start of data for the hash.
|
||||
// Fewer bytes may be skipped when `size` is small.
|
||||
|
@ -120,7 +119,7 @@ uint64_t RandomGenerator::CalculateSeed(const uint8_t* data, size_t size) {
|
|||
std::min(kHashDesiredLeadingSkipBytes,
|
||||
std::max<int64_t>(size_i64 - kHashDesiredMinBytes, 0));
|
||||
int64_t hash_end_i64 =
|
||||
std::max(hash_begin_i64 + kHashDesiredMaxBytes, size_i64);
|
||||
std::min(hash_begin_i64 + kHashDesiredMaxBytes, size_i64);
|
||||
size_t hash_begin = static_cast<size_t>(hash_begin_i64);
|
||||
size_t hash_size = static_cast<size_t>(hash_end_i64) - hash_begin;
|
||||
return HashBuffer(data + hash_begin, hash_size);
|
||||
|
|
Loading…
Reference in New Issue