diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-02 21:30:09 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-03 12:43:01 (GMT) |
commit | f080d232ef072976b28ca4b448dcb210b5941b2e (patch) | |
tree | 34d585105a58d37467dcc5c03b738ad24b6bff14 /src/corelib/tools | |
parent | 20cfe1e790295254370cf472df39813f864de7ea (diff) | |
download | Qt-f080d232ef072976b28ca4b448dcb210b5941b2e.zip Qt-f080d232ef072976b28ca4b448dcb210b5941b2e.tar.gz Qt-f080d232ef072976b28ca4b448dcb210b5941b2e.tar.bz2 |
fix canReadLine() erroneously returning true
the indexOf() call did not consider actualReadBufferSize and thus
scanned uninitialized memory for newlines.
Reviewed-by: phartman
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index c44346c..7c766cb 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -287,6 +287,33 @@ public: return -1; } + inline int indexOf(char c, int maxLength) const { + int index = 0; + int remain = qMin(size(), maxLength); + for (int i = 0; remain && i < buffers.size(); ++i) { + int start = 0; + int end = buffers.at(i).size(); + + if (i == 0) + start = head; + if (i == tailBuffer) + end = tail; + if (remain < end - start) { + end = start + remain; + remain = 0; + } else { + remain -= end - start; + } + const char *ptr = buffers.at(i).data() + start; + for (int j = start; j < end; ++j) { + if (*ptr++ == c) + return index; + ++index; + } + } + return -1; + } + inline int read(char *data, int maxLength) { int bytesToRead = qMin(size(), maxLength); int readSoFar = 0; |