summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qringbuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qringbuffer.cpp')
-rw-r--r--src/corelib/tools/qringbuffer.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp
index 66de1f59c06..f6ba5706993 100644
--- a/src/corelib/tools/qringbuffer.cpp
+++ b/src/corelib/tools/qringbuffer.cpp
@@ -340,14 +340,22 @@ void QRingBuffer::append(QByteArray &&qba)
bufferSize += qbaSize;
}
-qint64 QRingBuffer::readLine(char *data, qint64 maxLength)
+qint64 QRingBuffer::readLineWithoutTerminatingNull(char *data, qint64 maxLength)
{
- Q_ASSERT(data != nullptr && maxLength > 1);
+ Q_ASSERT(data != nullptr && maxLength > 0);
- --maxLength;
qint64 i = indexOf('\n', maxLength);
i = read(data, i >= 0 ? (i + 1) : maxLength);
+ return i;
+}
+
+qint64 QRingBuffer::readLine(char *data, qint64 maxLength)
+{
+ Q_ASSERT(maxLength > 1);
+
+ qint64 i = readLineWithoutTerminatingNull(data, maxLength - 1);
+
// Terminate it.
data[i] = '\0';
return i;