[llvm] r289607 - [libFuzzer] fix an UB (invalid shift) spotted by ubsan. The code worked fine by luck, because the way shifts actually work on clang+x86

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 14:49:14 PST 2016


Author: kcc
Date: Tue Dec 13 16:49:14 2016
New Revision: 289607

URL: http://llvm.org/viewvc/llvm-project?rev=289607&view=rev
Log:
[libFuzzer] fix an UB (invalid shift) spotted by ubsan. The code worked fine by luck, because the way shifts actually work on clang+x86

Modified:
    llvm/trunk/lib/Fuzzer/FuzzerTracePC.h

Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=289607&r1=289606&r2=289607&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Tue Dec 13 16:49:14 2016
@@ -126,7 +126,7 @@ size_t TracePC::CollectFeatures(Callback
     uint64_t Bundle = *reinterpret_cast<uint64_t*>(&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;




More information about the llvm-commits mailing list