summaryrefslogtreecommitdiffstats
path: root/libcxx/test/libcxx/fuzzing/geometric_distribution.pass.cpp
blob: acb07ef875a060dd25d8c93e319ca81607e4bd5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// -*- C++ -*-
//===------------------------ unique_copy.cpp -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <random>
#include <cstdint>

#include "fuzzer_test.h"

template <class Distribution>
int random_distribution_helper(const uint8_t *data, size_t size) {
  std::mt19937 engine;
  using ParamT = typename Distribution::param_type;
  if (size < sizeof(double))
    return 0;
  double Arg;
  memcpy(&Arg, data, sizeof(double));
  ParamT p(Arg);
  Distribution d(p);
  for (int I=0; I < 1000; ++I) {
    volatile auto res = d(engine);
    ((void)res);
  }
  return 0;
}

int FuzzRandom(const uint8_t *Data, size_t Size) {
  return random_distribution_helper<std::geometric_distribution<std::int16_t>>(Data, Size);
}
FUZZER_TEST(FuzzRandom);


OpenPOWER on IntegriCloud