summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2024-11-11 15:20:06 +0100
committerнаб <nabijaczleweli@nabijaczleweli.xyz>2024-11-11 15:52:43 +0100
commitd20575e93c38afb15fbc3e3bfc5e0e6a3903c299 (patch)
treee19e12bd61ba8767915604129831948184532f7b
parente59793e29ecb47c63b72de4f9d1e6d044a0ff6f2 (diff)
Turn std::unique_ptr<char[]/std::array<char>>(APT_BUFFER_SIZE) buffers into std::array<char, APT_BUFFER_SIZE>
-rw-r--r--apt-pkg/contrib/extracttar.cc10
-rw-r--r--apt-pkg/contrib/fileutl.cc7
-rw-r--r--cmdline/apt-dump-solver.cc9
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<unsigned char, 32*1024>>();
+ std::array<unsigned char, APT_BUFFER_SIZE> 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<unsigned long long>(Size, Junk->size());
- if (not InFd.Read(Junk->data(), ((Read + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block)))
+ auto const Read = std::min<unsigned long long>(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<unsigned char[]> Buf(new unsigned char[BufSize]);
+ std::array<unsigned char, APT_BUFFER_SIZE> 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 <apt-private/private-cmndline.h>
+#include <array>
#include <cstdio>
#include <iostream>
#include <memory>
@@ -134,10 +135,10 @@ int main(int argc,const char *argv[]) /*{{{*/
return WriteError("ERR_READ_ERROR", out, stdoutfd, Solver);
}
- std::unique_ptr<char[]> Buf(new char[APT_BUFFER_SIZE]);
+ std::array<char, APT_BUFFER_SIZE> 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();