From f6f82c2cc8a3dc8584cf19e521da93a8d17ba9eb Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Tue, 13 Dec 2016 22:49:14 +0000 Subject: [PATCH] [libFuzzer] fix an UB (invalid shift) spotted by ubsan. The code worked fine by luck, because the way shifts actually work on clang+x86 llvm-svn: 289607 --- llvm/lib/Fuzzer/FuzzerTracePC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.h b/llvm/lib/Fuzzer/FuzzerTracePC.h index df03739..e3f6f10 100644 --- a/llvm/lib/Fuzzer/FuzzerTracePC.h +++ b/llvm/lib/Fuzzer/FuzzerTracePC.h @@ -126,7 +126,7 @@ size_t TracePC::CollectFeatures(Callback CB) { uint64_t Bundle = *reinterpret_cast(&Counters[Idx]); if (!Bundle) continue; for (size_t i = Idx; i < Idx + Step; i++) { - uint8_t Counter = (Bundle >> (i * 8)) & 0xff; + uint8_t Counter = (Bundle >> ((i - Idx) * 8)) & 0xff; if (!Counter) continue; Counters[i] = 0; unsigned Bit = 0; -- 2.7.4