From: Pino Toscano Date: Sat, 19 Dec 2015 11:00:43 +0000 (+0100) Subject: CopyFile: fix BufSize to a sane value X-Git-Tag: 1.1.6~17 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/0c93e388d417ab03f2857903bb5791f4312cdbd0?ds=sidebyside CopyFile: fix BufSize to a sane value Commit e977b8b9234ac5db32f2f0ad7e183139b988340d tries to make BufSize calculated based on the size of the buffer; the problem is that std::unique_ptr::size() returns a pointer to the data, so sizeof() equals to the size of a pointer (later divided by sizeof(char), which is 1). The result is that the CopyFile copies in chunks of 8 bytes, which is not exactly ideal... As solution, declare BufSize in advance, and use its value to allocate the Buf array. Closes: #808381 --- diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 014f0ee51..86ca82cff 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -160,8 +160,8 @@ bool CopyFile(FileFd &From,FileFd &To) return false; // Buffered copy between fds - std::unique_ptr Buf(new unsigned char[64000]); - constexpr unsigned long long BufSize = sizeof(Buf.get())/sizeof(Buf.get()[0]); + constexpr size_t BufSize = 64000; + std::unique_ptr Buf(new unsigned char[BufSize]); unsigned long long ToRead = 0; do { if (From.Read(Buf.get(),BufSize, &ToRead) == false ||