Fixes for 32-bit build of fuzzers
This change resolves some type-related issues that were leading to
loss-of-precision warnings when compiling for i386 in OSS-Fuzz.
Change-Id: I77912d6b3824a0f942d0f54f1e62914f69e14d7d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66000
Auto-Submit: Alastair Donaldson <afdx@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/fuzzers/tint_spirv_tools_fuzzer/cli.cc b/fuzzers/tint_spirv_tools_fuzzer/cli.cc
index f304ed7..b942421 100644
--- a/fuzzers/tint_spirv_tools_fuzzer/cli.cc
+++ b/fuzzers/tint_spirv_tools_fuzzer/cli.cc
@@ -191,8 +191,8 @@
}
bool ParseUint32(const char* param, uint32_t* out) {
- auto value = strtoul(param, nullptr, 10);
- if (value > std::numeric_limits<uint32_t>::max()) {
+ uint64_t value = static_cast<uint64_t>(strtoul(param, nullptr, 10));
+ if (value > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) {
return false;
}
*out = static_cast<uint32_t>(value);
diff --git a/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc b/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc
index 18c072a..4d3b8aa 100644
--- a/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc
+++ b/fuzzers/tint_spirv_tools_fuzzer/fuzzer.cc
@@ -70,7 +70,8 @@
assert(!types.empty() && "At least one mutator type must be specified");
RandomGenerator generator(seed);
- auto mutator_type = types[generator.GetUInt64(types.size())];
+ auto mutator_type =
+ types[generator.GetUInt32(static_cast<uint32_t>(types.size()))];
const auto& mutator_params = context->params.mutator_params;
switch (mutator_type) {
diff --git a/fuzzers/tint_spirv_tools_fuzzer/spirv_opt_mutator.cc b/fuzzers/tint_spirv_tools_fuzzer/spirv_opt_mutator.cc
index 0b75ed3..d52d8ef 100644
--- a/fuzzers/tint_spirv_tools_fuzzer/spirv_opt_mutator.cc
+++ b/fuzzers/tint_spirv_tools_fuzzer/spirv_opt_mutator.cc
@@ -105,7 +105,8 @@
std::vector<std::string> passes;
while (passes.size() < num_of_passes) {
- auto idx = generator_.GetUInt64(opt_passes_.size());
+ auto idx =
+ generator_.GetUInt32(static_cast<uint32_t>(opt_passes_.size()));
passes.push_back(opt_passes_[idx]);
}
diff --git a/fuzzers/tint_spirv_tools_fuzzer/spirv_reduce_mutator.h b/fuzzers/tint_spirv_tools_fuzzer/spirv_reduce_mutator.h
index 2f25146..df5cf9b 100644
--- a/fuzzers/tint_spirv_tools_fuzzer/spirv_reduce_mutator.h
+++ b/fuzzers/tint_spirv_tools_fuzzer/spirv_reduce_mutator.h
@@ -73,14 +73,14 @@
template <typename T>
T* GetRandomElement(std::vector<T>* arr) {
assert(!arr->empty() && "Can't get random element from an empty vector");
- auto index = generator_.GetUInt64(arr->size());
+ auto index = generator_.GetUInt32(static_cast<uint32_t>(arr->size()));
return &(*arr)[index];
}
template <typename T>
T* GetRandomElement(std::vector<std::unique_ptr<T>>* arr) {
assert(!arr->empty() && "Can't get random element from an empty vector");
- auto index = generator_.GetUInt64(arr->size());
+ auto index = generator_.GetUInt32(static_cast<uint32_t>(arr->size()));
return (*arr)[index].get();
}
diff --git a/fuzzers/tint_spirv_tools_fuzzer/util.cc b/fuzzers/tint_spirv_tools_fuzzer/util.cc
index bd574a2..d25bfde 100644
--- a/fuzzers/tint_spirv_tools_fuzzer/util.cc
+++ b/fuzzers/tint_spirv_tools_fuzzer/util.cc
@@ -129,7 +129,7 @@
return false;
}
- auto size = file.tellg();
+ size_t size = static_cast<size_t>(file.tellg());
if (!file) {
return false;
}
@@ -139,7 +139,7 @@
return false;
}
- std::vector<char> binary(static_cast<size_t>(size));
+ std::vector<char> binary(size);
if (!file.read(binary.data(), size)) {
return false;
}