MCPcopy Create free account
hub / github.com/bytedance/bolt / randString

Function randString

bolt/vector/fuzzer/VectorFuzzer.cpp:602–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

600/// Options). Returns a StringView which uses `buf` as the underlying buffer.
601template <typename T>
602StringView randString(
603 FuzzerGenerator& rng,
604 const VectorFuzzer::Options& opts,
605 std::string& buf,
606 const bool doStringIncrementalGeneration,
607 T& reusablePartBuffer,
608 const size_t reusablePartLength) {
609 buf.clear();
610
611 std::u32string wbuf;
612 const size_t stringLength = opts.stringVariableLength
613 ? rand<uint32_t>(rng) % opts.stringLength
614 : opts.stringLength;
615 wbuf.resize(stringLength);
616
617 if (doStringIncrementalGeneration && reusablePartLength != 0) {
618 for (size_t i = 0; i < stringLength;) {
619 if (rand<bool>(rng)) {
620 // Reuse the reusable part.
621 size_t j;
622 for (j = 0; j < reusablePartLength && i + j < stringLength; ++j) {
623 wbuf[i + j] = reusablePartBuffer[j];
624 }
625 i += j;
626 } else {
627 // Randomly generate a character at the current index.
628 fillBuffer(wbuf, i, 1, rng, opts);
629 ++i;
630 }
631 }
632 } else {
633 // Randomly generate the entire string.
634 fillBuffer(wbuf, 0, stringLength, rng, opts);
635 }
636 buf.append(utf32ToUtf8(wbuf));
637 return StringView(buf);
638}
639
640template <TypeKind kind>
641VectorPtr fuzzConstantPrimitiveImpl(

Callers 2

fuzzFlatPrimitiveImplFunction · 0.85

Calls 5

utf32ToUtf8Function · 0.85
StringViewClass · 0.50
clearMethod · 0.45
resizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected