]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] replace std::random_shuffle with std::shuffle as std::random_shuffle...
authorKostya Serebryany <kcc@google.com>
Tue, 7 Feb 2017 22:37:34 +0000 (22:37 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 7 Feb 2017 22:37:34 +0000 (22:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294366 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerCorpus.h
lib/Fuzzer/FuzzerLoop.cpp
lib/Fuzzer/FuzzerMutate.cpp
lib/Fuzzer/FuzzerRandom.h

index 468d5e5ddc7012660afc2b9d367676768edcc62b..8c2f7039280ff1cdebd88462c0a9670765ee9d9b 100644 (file)
@@ -97,7 +97,7 @@ class InputCorpus {
   // Hypothesis: units added to the corpus last are more likely to be
   // interesting. This function gives more weight to the more recent units.
   size_t ChooseUnitIdxToMutate(Random &Rand) {
-    size_t Idx = static_cast<size_t>(CorpusDistribution(Rand.Get_mt19937()));
+    size_t Idx = static_cast<size_t>(CorpusDistribution(Rand));
     assert(Idx < Inputs.size());
     return Idx;
   }
index 8f4161ebe9809700dc99812e48a3dbac28b1b180..d15f2e20df4bbbef53c246548194778dd12cbee0 100644 (file)
@@ -460,7 +460,7 @@ void Fuzzer::RereadOutputCorpus(size_t MaxSize) {
 }
 
 void Fuzzer::ShuffleCorpus(UnitVector *V) {
-  std::random_shuffle(V->begin(), V->end(), MD.GetRand());
+  std::shuffle(V->begin(), V->end(), MD.GetRand());
   if (Options.PreferSmall)
     std::stable_sort(V->begin(), V->end(), [](const Unit &A, const Unit &B) {
       return A.size() < B.size();
index 6b1ac4e3b0b4739b07be99bd34534cbeded596a4..7c7e6688aa776a2008ab50bc6ee9aed635f915e8 100644 (file)
@@ -99,8 +99,7 @@ size_t MutationDispatcher::Mutate_ShuffleBytes(uint8_t *Data, size_t Size,
       Rand(std::min(Size, (size_t)8)) + 1; // [1,8] and <= Size.
   size_t ShuffleStart = Rand(Size - ShuffleAmount);
   assert(ShuffleStart + ShuffleAmount <= Size);
-  std::random_shuffle(Data + ShuffleStart, Data + ShuffleStart + ShuffleAmount,
-                      Rand);
+  std::shuffle(Data + ShuffleStart, Data + ShuffleStart + ShuffleAmount, Rand);
   return Size;
 }
 
index b1be0bb935fab94ec53ca83444ac227b3fbeb93a..8a1aa3ef5fdc145fee0bf1b43bcaa578fc18dcf9 100644 (file)
 #include <random>
 
 namespace fuzzer {
-class Random {
+class Random : public std::mt19937 {
  public:
-  Random(unsigned int seed) : R(seed) {}
-  size_t Rand() { return R(); }
+  Random(unsigned int seed) : std::mt19937(seed) {}
+  result_type operator()() { return this->std::mt19937::operator()(); }
+  size_t Rand() { return this->operator()(); }
   size_t RandBool() { return Rand() % 2; }
   size_t operator()(size_t n) { return n ? Rand() % n : 0; }
   intptr_t operator()(intptr_t From, intptr_t To) {
@@ -26,9 +27,6 @@ class Random {
     intptr_t RangeSize = To - From + 1;
     return operator()(RangeSize) + From;
   }
-  std::mt19937 &Get_mt19937() { return R; }
- private:
-  std::mt19937 R;
 };
 
 }  // namespace fuzzer