]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] fix an UB (invalid shift) spotted by ubsan. The code worked fine by luck...
authorKostya Serebryany <kcc@google.com>
Tue, 13 Dec 2016 22:49:14 +0000 (22:49 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 13 Dec 2016 22:49:14 +0000 (22:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerTracePC.h

index df037390c2afa921efa03199bf68ef01c899c560..e3f6f10a36f645aa867cacf7a9479d04f6378666 100644 (file)
@@ -126,7 +126,7 @@ size_t TracePC::CollectFeatures(Callback CB) {
     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;