Coverage Report

Created: 2026-04-12 07:01

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