Преглед изворни кода

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
Pino Toscano пре 10 година
родитељ
комит
0c93e388d4
1 измењених фајлова са 2 додато и 2 уклоњено
  1. 2 2
      apt-pkg/contrib/fileutl.cc

+ 2 - 2
apt-pkg/contrib/fileutl.cc

@@ -160,8 +160,8 @@ bool CopyFile(FileFd &From,FileFd &To)
       return false;
 
    // Buffered copy between fds
-   std::unique_ptr<unsigned char[]> 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<unsigned char[]> Buf(new unsigned char[BufSize]);
    unsigned long long ToRead = 0;
    do {
       if (From.Read(Buf.get(),BufSize, &ToRead) == false ||