char * corrupt_zeros(char * data, size_t * dataSz) { // Choose between zero corruption methods // 0. Insert zeros in to the bitstream // 1. Replace random bytes with zeros int choice = randomInt(0, 1); size_t corruptLoc = random_offset(*dataSz); size_t corruptSize = randomInt(1, 0x100); // we can't corrupt this crap TODO fix this if(*dataSz < CORRUPT_START_MIN) return data; char * replacement = calloc(corruptSize, sizeof(char)); if(!replacement) return data; memset(replacement, 0x0, corruptSize); if(choice == 0) { data = insertBytes(data, dataSz, replacement, corruptSize, corruptLoc); } else if(choice == 1) { data = replaceBytes(data, dataSz, replacement, corruptSize, corruptLoc); } return data; }
bool StringCell::fill(UnicodeChar unicodeChar, SliceIndexType start, SliceIndexType end) { assert(unicodeChar.isValid()); CharRange range = charRange(start, end); if (range.isNull()) { // Invalid range return false; } // Encode the new character utf8::EncodedChar encoded(utf8::encodeChar(unicodeChar)); return replaceBytes(range, encoded.data, encoded.size, range.charCount); }
bool StringCell::replace(CharLengthType offset, const StringCell *from, SliceIndexType fromStart, SliceIndexType fromEnd) { CharRange fromRange = const_cast<StringCell*>(from)->charRange(fromStart, fromEnd); if (fromRange.isNull()) { return false; } CharRange toRange = charRange(offset, offset + fromRange.charCount); if (toRange.isNull() || (toRange.charCount != fromRange.charCount)) { return false; } return replaceBytes(toRange, fromRange.startPointer, fromRange.byteCount(), 1); }