]> git.saurik.com Git - apt.git/commitdiff
simple_buffer::write: Use free() instead of maxsize - size()
authorJulian Andres Klode <jak@debian.org>
Mon, 1 Feb 2016 15:25:03 +0000 (16:25 +0100)
committerJulian Andres Klode <jak@debian.org>
Mon, 1 Feb 2016 15:25:03 +0000 (16:25 +0100)
We want to check whether the amount of free space is smaller
than the requested write size. Checking maxsize - size() is
incorrect for bufferstart >= 0, as size() = end - start.

Gbp-Dch: ignore

apt-pkg/contrib/fileutl.cc

index 4347c55ad3d633bc411257d4dad7b0b663645b48..004df3fe8d33ffc8e793543570723ba75b3198c0 100644 (file)
@@ -968,9 +968,9 @@ struct APT_HIDDEN simple_buffer {                                                   /*{{{*/
    }
    ssize_t write(const void *from, unsigned long long requested_size) APT_MUSTCHECK
    {
-      if (buffersize_max - size() < requested_size)
-        requested_size = buffersize_max - size();
-      memcpy(buffer + bufferend, from, requested_size);
+      if (free() < requested_size)
+        requested_size = free();
+      memcpy(getend(), from, requested_size);
       bufferend += requested_size;
       if (bufferstart == bufferend)
         bufferstart = bufferend = 0;