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"
16 // Cross A and B, store the result (ap to MaxLen bytes) in U.
17 void CrossOver(const Unit &A, const Unit &B, Unit *U, size_t MaxLen) {
18 size_t Size = rand() % MaxLen + 1;
24 while (U->size() < Size && (PosA < A.size() || PosB < B.size())) {
25 // Merge a part of V into U.
26 size_t SizeLeftU = Size - U->size();
27 if (*Pos < V->size()) {
28 size_t SizeLeftV = V->size() - *Pos;
29 size_t MaxExtraSize = std::min(SizeLeftU, SizeLeftV);
30 size_t ExtraSize = rand() % MaxExtraSize + 1;
31 U->insert(U->end(), V->begin() + *Pos, V->begin() + *Pos + ExtraSize);
35 // Use the other Unit on the next iteration.