From d20575e93c38afb15fbc3e3bfc5e0e6a3903c299 Mon Sep 17 00:00:00 2001 From: наб Date: Mon, 11 Nov 2024 15:20:06 +0100 Subject: Turn std::unique_ptr>(APT_BUFFER_SIZE) buffers into std::array --- apt-pkg/contrib/extracttar.cc | 10 +++++----- apt-pkg/contrib/fileutl.cc | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/extracttar.cc b/apt-pkg/contrib/extracttar.cc index dff9326a1..7b545de17 100644 --- a/apt-pkg/contrib/extracttar.cc +++ b/apt-pkg/contrib/extracttar.cc @@ -132,7 +132,7 @@ bool ExtractTar::Go(pkgDirStream &Stream) // Loop over all blocks string LastLongLink, ItemLink; string LastLongName, ItemName; - auto Junk = std::make_unique>(); + std::array Junk; while (1) { bool BadRecord = false; @@ -295,19 +295,19 @@ bool ExtractTar::Go(pkgDirStream &Stream) auto Size = Itm.Size; do { - auto const Read = std::min(Size, Junk->size()); - if (not InFd.Read(Junk->data(), ((Read + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block))) + auto const Read = std::min(Size, Junk.size()); + if (not InFd.Read(Junk.data(), ((Read + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block))) return false; if (Fd > 0) { - if (not FileFd::Write(Fd, Junk->data(), Read)) + if (not FileFd::Write(Fd, Junk.data(), Read)) return Stream.Fail(Itm, Fd); } // An Fd of -2 means to send to a special processing function else if (Fd == -2) { - if (not Stream.Process(Itm, Junk->data(), Read, Itm.Size - Size)) + if (not Stream.Process(Itm, Junk.data(), Read, Itm.Size - Size)) return Stream.Fail(Itm, Fd); } diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index db97738e3..957d068de 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -176,12 +176,11 @@ bool CopyFile(FileFd &From,FileFd &To) return false; // Buffered copy between fds - constexpr size_t BufSize = APT_BUFFER_SIZE; - std::unique_ptr Buf(new unsigned char[BufSize]); + std::array Buf; unsigned long long ToRead = 0; do { - if (From.Read(Buf.get(),BufSize, &ToRead) == false || - To.Write(Buf.get(),ToRead) == false) + if (From.Read(Buf.data(),Buf.size(), &ToRead) == false || + To.Write(Buf.data(),ToRead) == false) return false; } while (ToRead != 0); -- cgit v1.2.3-70-g09d2