1092QDataStream &QDataStream::readBytes(
char *&s, qint64 &l)
1098 qint64 length = readQSizeType(*
this);
1102 qsizetype len = qsizetype(length);
1103 if (length != len || length < 0) {
1104 setStatus(SizeLimitExceeded);
1108 qsizetype step = (dev->bytesAvailable() >= len) ? len : 1024 * 1024;
1109 qsizetype allocated = 0;
1110 std::unique_ptr<
char[]> curBuf =
nullptr;
1112 constexpr qsizetype StepIncreaseThreshold = std::numeric_limits<qsizetype>::max() / 2;
1114 qsizetype blockSize = qMin(step, len - allocated);
1115 const qsizetype n = allocated + blockSize + 1;
1116 if (
const auto prevBuf = std::exchange(curBuf, q20::make_unique_for_overwrite<
char[]>(n)))
1117 memcpy(curBuf.get(), prevBuf.get(), allocated);
1118 if (readBlock(curBuf.get() + allocated, blockSize) != blockSize)
1120 allocated += blockSize;
1121 if (step <= StepIncreaseThreshold)
1123 }
while (allocated < len);
1125 s = curBuf.release();