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 +++---- cmdline/apt-dump-solver.cc | 9 +++++---- 3 files changed, 13 insertions(+), 13 deletions(-) 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); diff --git a/cmdline/apt-dump-solver.cc b/cmdline/apt-dump-solver.cc index 3e590355e..05142d9dd 100644 --- a/cmdline/apt-dump-solver.cc +++ b/cmdline/apt-dump-solver.cc @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -134,10 +135,10 @@ int main(int argc,const char *argv[]) /*{{{*/ return WriteError("ERR_READ_ERROR", out, stdoutfd, Solver); } - std::unique_ptr Buf(new char[APT_BUFFER_SIZE]); + std::array Buf; unsigned long long ToRead = 0; do { - if (input.Read(Buf.get(), APT_BUFFER_SIZE, &ToRead) == false) + if (input.Read(Buf.data(), Buf.size(), &ToRead) == false) { std::ostringstream out; out << "Writing EDSP solver input to file '" << filename << "' failed as reading from stdin failed!\n"; @@ -145,9 +146,9 @@ int main(int argc,const char *argv[]) /*{{{*/ } if (ToRead == 0) break; - if (forward.IsOpen() && forward.Failed() == false && forward.Write(Buf.get(),ToRead) == false) + if (forward.IsOpen() && forward.Failed() == false && forward.Write(Buf.data(),ToRead) == false) forward.Close(); - if (dump.IsOpen() && dump.Failed() == false && dump.Write(Buf.get(),ToRead) == false) + if (dump.IsOpen() && dump.Failed() == false && dump.Write(Buf.data(),ToRead) == false) dump.Close(); } while (true); input.Close(); -- cgit v1.2.3-70-g09d2