MCPcopy Create free account
hub / github.com/HexHive/NASS / InsertPartOf

Method InsertPartOf

fuzz/libfuzzer/FuzzerMutate.cpp:338–360  ·  view source on GitHub ↗

Inserts part of From[0,ToSize) into To. Returns new size of To on success or 0 on failure.

Source from the content-addressed store, hash-verified

336// Inserts part of From[0,ToSize) into To.
337// Returns new size of To on success or 0 on failure.
338size_t MutationDispatcher::InsertPartOf(const uint8_t *From, size_t FromSize,
339 uint8_t *To, size_t ToSize,
340 size_t MaxToSize) {
341 if (ToSize >= MaxToSize) return 0;
342 size_t AvailableSpace = MaxToSize - ToSize;
343 size_t MaxCopySize = std::min(AvailableSpace, FromSize);
344 size_t CopySize = Rand(MaxCopySize) + 1;
345 size_t FromBeg = Rand(FromSize - CopySize + 1);
346 assert(FromBeg + CopySize <= FromSize);
347 size_t ToInsertPos = Rand(ToSize + 1);
348 assert(ToInsertPos + CopySize <= MaxToSize);
349 size_t TailSize = ToSize - ToInsertPos;
350 if (To == From) {
351 MutateInPlaceHere.resize(MaxToSize);
352 memcpy(MutateInPlaceHere.data(), From + FromBeg, CopySize);
353 memmove(To + ToInsertPos + CopySize, To + ToInsertPos, TailSize);
354 memmove(To + ToInsertPos, MutateInPlaceHere.data(), CopySize);
355 } else {
356 memmove(To + ToInsertPos + CopySize, To + ToInsertPos, TailSize);
357 memmove(To + ToInsertPos, From + FromBeg, CopySize);
358 }
359 return ToSize + CopySize;
360}
361
362size_t MutationDispatcher::Mutate_CopyPart(uint8_t *Data, size_t Size,
363 size_t MaxSize) {

Callers

nothing calls this directly

Calls 2

resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected