Coverage Report

Created: 2026-08-13 06:30

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
590
void FuzzChained(const uint8_t *data, size_t size) {
32
590
  FuzzedDataProvider fdp(data, size);
33
590
  std::vector<char> v;
34
45.7k
  for (int i = 0; i < fdp.ConsumeIntegralInRange<int>(1, 1024); i++) {
35
45.1k
    v.push_back((char)fdp.ConsumeIntegral<char>());
36
45.1k
  }
37
590
  const auto ch = chain(v, v, v);
38
590
  std::vector<char> v2(std::begin(ch), std::end(ch));
39
590
}
40
41
20.8k
int length(const std::string &s) { return s.size(); }
42
43
590
void FuzzGroupby(const uint8_t *data, size_t size) {
44
590
  FuzzedDataProvider fdp(data, size);
45
590
  std::vector<std::string> v;
46
14.3k
  for (int i = 0; i < fdp.ConsumeIntegralInRange<int>(1, 1024); i++) {
47
13.7k
    v.push_back(fdp.ConsumeRandomLengthString());
48
13.7k
  }
49
3.85k
  for (auto &&gb : groupby(v, length)) {
50
3.85k
  }
51
590
}
52
53
590
void FuzzCycle(const uint8_t *data, size_t size) {
54
590
  FuzzedDataProvider fdp(data, size);
55
590
  std::vector<int> v;
56
38.5k
  for (int i = 0; i < fdp.ConsumeIntegralInRange<int>(1, 1024); i++) {
57
37.9k
    v.push_back(fdp.ConsumeIntegral<int>());
58
37.9k
  }
59
590
  auto ch = cycle(v);
60
61
590
  std::vector<int> o;
62
590
  size_t count = 0;
63
885k
  for (auto val : ch) {
64
885k
    o.push_back(val);
65
885k
    count++;
66
885k
    if (count > 1500) {
67
590
      break;
68
590
    }
69
885k
  }
70
590
}
71
72
590
void FuzzCombinations(const uint8_t *data, size_t size) {
73
590
  FuzzedDataProvider fdp(data, size);
74
590
  std::string s = fdp.ConsumeRandomLengthString();
75
590
  std::vector<std::vector<char>> sc;
76
590
  size_t count = 0;
77
334k
  for (auto &&v : combinations(s, fdp.ConsumeIntegralInRange(1, 16))) {
78
334k
    sc.emplace_back(std::begin(v), std::end(v));
79
334k
    count++;
80
334k
    if (count > 1500) {
81
200
      break;
82
200
    }
83
334k
  }
84
590
}
85
86
590
void FuzzCompress(const uint8_t *data, size_t size) {
87
590
  FuzzedDataProvider fdp(data, size);
88
590
  std::vector<int> ivec;
89
590
  std::vector<bool> bvec;
90
59.5k
  for (int i = 0; i < 100; i++) {
91
59.0k
    ivec.push_back(fdp.ConsumeIntegralInRange(1, 1000000));
92
59.0k
    bvec.push_back(fdp.ConsumeBool());
93
59.0k
  }
94
590
  auto c = compress(ivec, bvec);
95
590
  std::vector<int> v(std::begin(c), std::end(c));
96
590
  const auto &c2 = c;
97
590
  (void)(std::begin(c) == std::end(c2));
98
590
}
99
100
590
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
101
590
  FuzzChained(data, size);
102
590
  FuzzGroupby(data, size);
103
590
  FuzzCycle(data, size);
104
590
  FuzzCombinations(data, size);
105
590
  FuzzCompress(data, size);
106
590
  return 0;
107
590
}