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