summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2015-12-26 22:06:14 +0100
committerJulian Andres Klode <jak@debian.org>2015-12-26 22:46:04 +0100
commita9024b1be2e26c3c6b1f67093ddbf7602636ec9f (patch)
tree07e68722e2d546fd48422cff3d11a519f2bcbb3a /apt-pkg
parent2658e1c5487d0bb9c6223cf149a48f47e8d10b4d (diff)
Change InternalReadLine to always use buffer.read() return value
This is mostly a documentation issue, as the size we want to read is always less than or equal to the size of the buffer, so the return value will be the same as the size argument. Nonetheless, people wondered about it, and it seems clearer to just always use the return value.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/fileutl.cc20
1 files changed, 8 insertions, 12 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index c4ff36a13..aa5831f58 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -932,7 +932,7 @@ protected:
bool empty() { return bufferend <= bufferstart; }
unsigned long long size() { return bufferend-bufferstart; }
void reset() { bufferend = bufferstart = 0; }
- ssize_t read(void *to, unsigned long long requested_size)
+ ssize_t read(void *to, unsigned long long requested_size) APT_MUSTCHECK
{
if (size() < requested_size)
requested_size = size();
@@ -995,19 +995,15 @@ public:
unsigned long long const OutputSize = std::min(Size, buffer.size());
char const * const newline = static_cast<char const * const>(memchr(buffer.get(), '\n', OutputSize));
+ // Read until end of line or up to Size bytes from the buffer.
+ unsigned long long actualread = buffer.read(To,
+ (newline != nullptr)
+ ? (newline - buffer.get()) + 1
+ : OutputSize);
+ To += actualread;
+ Size -= actualread;
if (newline != nullptr)
- {
- size_t length = (newline - buffer.get()) + 1;
- buffer.read(To, length);
- To += length;
break;
- }
- else
- {
- buffer.read(To, OutputSize);
- To += OutputSize;
- Size -= OutputSize;
- }
} while (Size > 0);
*To = '\0';
return InitialTo;