Coverage Report

Created: 2026-06-10 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cppitertools/fuzz_cppitertools.cpp
Line
Count
Source
1
/* Copyright 2023 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
#include <chain.hpp>
13
#include <combinations.hpp>
14
#include <compress.hpp>
15
#include <cycle.hpp>
16
#include <groupby.hpp>
17
18
#include <fuzzer/FuzzedDataProvider.h>
19
20
#include <iterator>
21
#include <string>
22
#include <utility>
23
#include <vector>
24
25
using iter::chain;
26
using iter::combinations;
27
using iter::compress;
28
using iter::cycle;
29
using iter::groupby;
30
31
594
void FuzzChained(const uint8_t *data, size_t size) {
32
594
  FuzzedDataProvider fdp(data, size);
33
594
  std::vector<char> v;
34
55.6k
  for (int i = 0; i < fdp.ConsumeIntegralInRange<int>(1, 1024); i++) {
35
55.0k
    v.push_back((char)fdp.ConsumeIntegral<char>());
36
55.0k
  }
37
594
  const auto ch = chain(v, v, v);
38
594
  std::vector<char> v2(std::begin(ch), std::end(ch));
39
594
}
40
41
21.5k
int length(const std::string &s) { return s.size(); }
42
43
594
void FuzzGroupby(const uint8_t *data, size_t size) {
44
594
  FuzzedDataProvider fdp(data, size);
45
594
  std::vector<std::string> v;
46
14.4k
  for (int i = 0; i < fdp.ConsumeIntegralInRange<int>(1, 1024); i++) {
47
13.9k
    v.push_back(fdp.ConsumeRandomLengthString());
48
13.9k
  }
49
4.09k
  for (auto &&gb : groupby(v, length)) {
50
4.09k
  }
51
594
}
52
53
594
void FuzzCycle(const uint8_t *data, size_t size) {
54
594
  FuzzedDataProvider fdp(data, size);
55
594
  std::vector<int> v;
56
41.8k
  for (int i = 0; i < fdp.ConsumeIntegralInRange<int>(1, 1024); i++) {
57
41.2k
    v.push_back(fdp.ConsumeIntegral<int>());
58
41.2k
  }
59
594
  auto ch = cycle(v);
60
61
594
  std::vector<int> o;
62
594
  size_t count = 0;
63
891k
  for (auto val : ch) {
64
891k
    o.push_back(val);
65
891k
    count++;
66
891k
    if (count > 1500) {
67
594
      break;
68
594
    }
69
891k
  }
70
594
}
71
72
594
void FuzzCombinations(const uint8_t *data, size_t size) {
73
594
  FuzzedDataProvider fdp(data, size);
74
594
  std::string s = fdp.ConsumeRandomLengthString();
75
594
  std::vector<std::vector<char>> sc;
76
594
  size_t count = 0;
77
337k
  for (auto &&v : combinations(s, fdp.ConsumeIntegralInRange(1, 16))) {
78
337k
    sc.emplace_back(std::begin(v), std::end(v));
79
337k
    count++;
80
337k
    if (count > 1500) {
81
203
      break;
82
203
    }
83
337k
  }
84
594
}
85
86
594
void FuzzCompress(const uint8_t *data, size_t size) {
87
594
  FuzzedDataProvider fdp(data, size);
88
594
  std::vector<int> ivec;
89
594
  std::vector<bool> bvec;
90
59.9k
  for (int i = 0; i < 100; i++) {
91
59.4k
    ivec.push_back(fdp.ConsumeIntegralInRange(1, 1000000));
92
59.4k
    bvec.push_back(fdp.ConsumeBool());
93
59.4k
  }
94
594
  auto c = compress(ivec, bvec);
95
594
  std::vector<int> v(std::begin(c), std::end(c));
96
594
  const auto &c2 = c;
97
594
  (void)(std::begin(c) == std::end(c2));
98
594
}
99
100
594
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
101
594
  FuzzChained(data, size);
102
594
  FuzzGroupby(data, size);
103
594
  FuzzCycle(data, size);
104
594
  FuzzCombinations(data, size);
105
594
  FuzzCompress(data, size);
106
594
  return 0;
107
594
}