1 //===- FuzzerCrossOver.cpp - Cross over two test inputs -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Cross over test inputs.
10 //===----------------------------------------------------------------------===//
12 #include "FuzzerInternal.h"
17 // Cross A and B, store the result (ap to MaxLen bytes) in U.
18 void CrossOver(const Unit &A, const Unit &B, Unit *U, size_t MaxLen) {
19 size_t Size = rand() % MaxLen + 1;
25 while (U->size() < Size && (PosA < A.size() || PosB < B.size())) {
26 // Merge a part of V into U.
27 size_t SizeLeftU = Size - U->size();
28 if (*Pos < V->size()) {
29 size_t SizeLeftV = V->size() - *Pos;
30 size_t MaxExtraSize = std::min(SizeLeftU, SizeLeftV);
31 size_t ExtraSize = rand() % MaxExtraSize + 1;
32 U->insert(U->end(), V->begin() + *Pos, V->begin() + *Pos + ExtraSize);
36 // Use the other Unit on the next iteration.