diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-07-13 16:27:38 +0200 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-07-17 09:32:19 +0200 |
commit | fa8401f9bfe81f4853bf9b67bff42a2cebffc10f (patch) | |
tree | 869c64f3d5b7fb8349a3909af09d8cca7fca6e61 /compiler-rt | |
parent | d17f455a6348806c73641e742af08b0a974e13d5 (diff) | |
download | llvm-fa8401f9bfe81f4853bf9b67bff42a2cebffc10f.zip llvm-fa8401f9bfe81f4853bf9b67bff42a2cebffc10f.tar.gz llvm-fa8401f9bfe81f4853bf9b67bff42a2cebffc10f.tar.bz2 |
[compiler-rt][NFC] Avoid implicit-integer-sign-change in FuzzedDataProvider::ConsumeIntegralInRange
This makes the implicit conversion that is happening explicit.
Otherwise, each user is forced to suppress this
implicit-integer-sign-change runtime error in their their UBSAN
suppressions file.
For example, the runtime error might look like:
runtime error: implicit conversion from type 'long' of value -9223372036854775808 (64-bit, signed) to type 'uint64_t' (aka 'unsigned long') changed the value to 9223372036854775808 (64-bit, unsigned)
#0 0x55fe29dea91d in long FuzzedDataProvider::ConsumeIntegralInRange<long>(long, long) src/./test/fuzz/FuzzedDataProvider.h:233:25
[...]
SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-sign-change test/fuzz/FuzzedDataProvider.h:233:25 in
Differential Revision: https://reviews.llvm.org/D155206
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/include/fuzzer/FuzzedDataProvider.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler-rt/include/fuzzer/FuzzedDataProvider.h b/compiler-rt/include/fuzzer/FuzzedDataProvider.h index 71cb427..8a8214b 100644 --- a/compiler-rt/include/fuzzer/FuzzedDataProvider.h +++ b/compiler-rt/include/fuzzer/FuzzedDataProvider.h @@ -209,7 +209,7 @@ T FuzzedDataProvider::ConsumeIntegralInRange(T min, T max) { abort(); // Use the biggest type possible to hold the range and the result. - uint64_t range = static_cast<uint64_t>(max) - min; + uint64_t range = static_cast<uint64_t>(max) - static_cast<uint64_t>(min); uint64_t result = 0; size_t offset = 0; @@ -230,7 +230,7 @@ T FuzzedDataProvider::ConsumeIntegralInRange(T min, T max) { if (range != std::numeric_limits<decltype(range)>::max()) result = result % (range + 1); - return static_cast<T>(min + result); + return static_cast<T>(static_cast<uint64_t>(min) + result); } // Returns a floating point value in the range [Type's lowest, Type's max] by |