summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2024-11-11 15:28:27 +0000
committerJulian Andres Klode <jak@debian.org>2024-11-11 15:28:27 +0000
commitaefccbe09722c6a7a0911cb882622c96215eeec2 (patch)
treee19e12bd61ba8767915604129831948184532f7b
parentf4e0e9daf221e840e122b0ffa97007aa512020a6 (diff)
parentd20575e93c38afb15fbc3e3bfc5e0e6a3903c299 (diff)
Merge branch 'stdarray' into 'main'
Fold char[APT_BUFFER_SIZE] and unique_ptr<char, APT_BUFFER_SIZE> into std::array<char, APT_BUFFER_SIZE> See merge request apt-team/apt!386
-rw-r--r--apt-pkg/contrib/extracttar.cc10
-rw-r--r--apt-pkg/contrib/fileutl.cc42
-rw-r--r--apt-pkg/contrib/hashes.cc17
-rw-r--r--cmdline/apt-dump-solver.cc9
-rw-r--r--debian/tests/control2
-rw-r--r--ftparchive/apt-ftparchive.cc10
-rw-r--r--ftparchive/multicompress.cc13
-rw-r--r--ftparchive/sources.cc8
-rw-r--r--methods/store.cc9
-rw-r--r--test/integration/framework7
-rwxr-xr-xtest/integration/test-apt-update-simple7
11 files changed, 67 insertions, 67 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 4ad7b4cd5..957d068de 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -59,6 +59,7 @@
#include <unistd.h>
#include <algorithm>
+#include <array>
#include <memory>
#include <set>
@@ -175,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);
@@ -1246,12 +1246,11 @@ public:
}
virtual bool InternalSkip(unsigned long long Over)
{
- unsigned long long constexpr buffersize = APT_BUFFER_SIZE;
- char buffer[buffersize];
+ std::array<char, APT_BUFFER_SIZE> buffer;
while (Over != 0)
{
- unsigned long long toread = std::min(buffersize, Over);
- if (filefd->Read(buffer, toread) == false)
+ auto toread = std::min<unsigned long long>(buffer.size(), Over);
+ if (filefd->Read(buffer.data(), toread) == false)
return filefd->FileFdError("Unable to seek ahead %llu",Over);
Over -= toread;
}
@@ -1273,10 +1272,10 @@ public:
{
unsigned long long size = 0;
unsigned long long const oldSeek = filefd->Tell();
- char ignore[APT_BUFFER_SIZE];
+ std::array<char, APT_BUFFER_SIZE> ignore;
unsigned long long read = 0;
do {
- if (filefd->Read(ignore, sizeof(ignore), &read) == false)
+ if (filefd->Read(ignore.data(), ignore.size(), &read) == false)
{
filefd->Seek(oldSeek);
return 0;
@@ -1994,7 +1993,7 @@ class APT_HIDDEN LzmaFileFdPrivate: public FileFdPrivate { /*{{{*/
struct LZMAFILE {
FILE* file;
FileFd * const filefd;
- uint8_t buffer[APT_BUFFER_SIZE];
+ std::array<unsigned char, APT_BUFFER_SIZE> buffer;
lzma_stream stream;
lzma_ret err;
bool eof;
@@ -2005,19 +2004,18 @@ class APT_HIDDEN LzmaFileFdPrivate: public FileFdPrivate { /*{{{*/
{
if (compressing == true && filefd->Failed() == false)
{
- size_t constexpr buffersize = sizeof(buffer)/sizeof(buffer[0]);
while(true)
{
- stream.avail_out = buffersize;
- stream.next_out = buffer;
+ stream.avail_out = buffer.size();
+ stream.next_out = buffer.data();
err = lzma_code(&stream, LZMA_FINISH);
if (err != LZMA_OK && err != LZMA_STREAM_END)
{
_error->Error("~LZMAFILE: Compress finalisation failed");
break;
}
- size_t const n = buffersize - stream.avail_out;
- if (n && fwrite(buffer, 1, n, file) != n)
+ size_t const n = buffer.size() - stream.avail_out;
+ if (n && fwrite(buffer.data(), 1, n, file) != n)
{
_error->Errno("~LZMAFILE",_("Write error"));
break;
@@ -2112,8 +2110,8 @@ public:
lzma->stream.avail_out = Size;
if (lzma->stream.avail_in == 0)
{
- lzma->stream.next_in = lzma->buffer;
- lzma->stream.avail_in = fread(lzma->buffer, 1, sizeof(lzma->buffer)/sizeof(lzma->buffer[0]), lzma->file);
+ lzma->stream.next_in = lzma->buffer.data();
+ lzma->stream.avail_in = fread(lzma->buffer.data(), 1, lzma->buffer.size(), lzma->file);
}
lzma->err = lzma_code(&lzma->stream, LZMA_RUN);
if (lzma->err == LZMA_STREAM_END)
@@ -2147,13 +2145,13 @@ public:
ssize_t Res;
lzma->stream.next_in = (uint8_t *)From;
lzma->stream.avail_in = Size;
- lzma->stream.next_out = lzma->buffer;
- lzma->stream.avail_out = sizeof(lzma->buffer)/sizeof(lzma->buffer[0]);
+ lzma->stream.next_out = lzma->buffer.data();
+ lzma->stream.avail_out = lzma->buffer.size();
lzma->err = lzma_code(&lzma->stream, LZMA_RUN);
if (lzma->err != LZMA_OK)
return -1;
- size_t const n = sizeof(lzma->buffer)/sizeof(lzma->buffer[0]) - lzma->stream.avail_out;
- size_t const m = (n == 0) ? 0 : fwrite(lzma->buffer, 1, n, lzma->file);
+ size_t const n = lzma->buffer.size() - lzma->stream.avail_out;
+ size_t const m = (n == 0) ? 0 : fwrite(lzma->buffer.data(), 1, n, lzma->file);
if (m != n)
{
Res = -1;
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 7ff5f9e9f..0ad51fff0 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -21,6 +21,7 @@
#include <apt-pkg/tagfile.h>
#include <algorithm>
+#include <array>
#include <cassert>
#include <cstddef>
#include <cstdlib>
@@ -372,33 +373,33 @@ bool Hashes::Add(const unsigned char * const Data, unsigned long long const Size
}
bool Hashes::AddFD(int const Fd,unsigned long long Size)
{
- unsigned char Buf[APT_BUFFER_SIZE];
+ std::array<unsigned char, APT_BUFFER_SIZE> Buf;
bool const ToEOF = (Size == UntilEOF);
while (Size != 0 || ToEOF)
{
- decltype(Size) n = sizeof(Buf);
+ decltype(Size) n = Buf.size();
if (!ToEOF) n = std::min(Size, n);
- ssize_t const Res = read(Fd,Buf,n);
+ ssize_t const Res = read(Fd,Buf.data(),n);
if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
return false;
if (ToEOF && Res == 0) // EOF
break;
Size -= Res;
- if (Add(Buf, Res) == false)
+ if (Add(Buf.data(), Res) == false)
return false;
}
return true;
}
bool Hashes::AddFD(FileFd &Fd,unsigned long long Size)
{
- unsigned char Buf[APT_BUFFER_SIZE];
+ std::array<unsigned char, APT_BUFFER_SIZE> Buf;
bool const ToEOF = (Size == 0);
while (Size != 0 || ToEOF)
{
- decltype(Size) n = sizeof(Buf);
+ decltype(Size) n = Buf.size();
if (!ToEOF) n = std::min(Size, n);
decltype(Size) a = 0;
- if (Fd.Read(Buf, n, &a) == false) // error
+ if (Fd.Read(Buf.data(), n, &a) == false) // error
return false;
if (ToEOF == false)
{
@@ -408,7 +409,7 @@ bool Hashes::AddFD(FileFd &Fd,unsigned long long Size)
else if (a == 0) // EOF
break;
Size -= a;
- if (Add(Buf, a) == false)
+ if (Add(Buf.data(), a) == false)
return false;
}
return true;
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();
diff --git a/debian/tests/control b/debian/tests/control
index d2b2e32c6..eaee89942 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -8,4 +8,4 @@ Depends: @, @builddeps@, dpkg (>= 1.20.8), fakeroot, wget, stunnel4, lsof, db-ut
gnupg (>= 2) | gnupg2, gnupg1 | gnupg (<< 2),
gpgv (>= 2) | gpgv2, gpgv1 | gpgv (<< 2),
libfile-fcntllock-perl, python3-apt, aptitude,
- valgrind, gdb-minimal | gdb
+ valgrind-if-available, gdb-minimal | gdb
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc
index d1ecaa547..9c86d18dd 100644
--- a/ftparchive/apt-ftparchive.cc
+++ b/ftparchive/apt-ftparchive.cc
@@ -387,17 +387,15 @@ bool PackageMap::GenContents(Configuration &Setup,
return false;
unsigned long long Size = Head.Size();
- unsigned char Buf[APT_BUFFER_SIZE];
+ std::array<unsigned char, APT_BUFFER_SIZE> Buf;
while (Size != 0)
{
- unsigned long long ToRead = Size;
- if (Size > sizeof(Buf))
- ToRead = sizeof(Buf);
+ auto ToRead = std::min<unsigned long long>(Size, Buf.size());
- if (Head.Read(Buf,ToRead) == false)
+ if (Head.Read(Buf.data(),ToRead) == false)
return false;
- if (Comp.Input.Write(Buf, ToRead) == false)
+ if (Comp.Input.Write(Buf.data(), ToRead) == false)
return _error->Errno("fwrite",_("Error writing header to contents file"));
Size -= ToRead;
diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc
index ac85670d5..cbbbe3518 100644
--- a/ftparchive/multicompress.cc
+++ b/ftparchive/multicompress.cc
@@ -21,6 +21,7 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/strutl.h>
+#include <array>
#include <cctype>
#include <sys/stat.h>
#include <sys/time.h>
@@ -264,23 +265,23 @@ bool MultiCompress::Child(int const &FD)
/* Okay, now we just feed data from FD to all the other FDs. Also
stash a hash of the data to use later. */
SetNonBlock(FD,false);
- unsigned char Buffer[32*1024];
+ std::array<unsigned char, APT_BUFFER_SIZE> Buffer;
unsigned long long FileSize = 0;
Hashes MD5(Hashes::MD5SUM);
while (1)
{
WaitFd(FD,false);
- int Res = read(FD,Buffer,sizeof(Buffer));
+ int Res = read(FD,Buffer.data(),Buffer.size());
if (Res == 0)
break;
if (Res < 0)
continue;
- MD5.Add(Buffer,Res);
+ MD5.Add(Buffer.data(),Res);
FileSize += Res;
for (Files *I = Outputs; I != 0; I = I->Next)
{
- if (I->TmpFile.Write(Buffer, Res) == false)
+ if (I->TmpFile.Write(Buffer.data(), Res) == false)
{
_error->Errno("write",_("IO to subprocess/file failed"));
break;
@@ -319,12 +320,12 @@ bool MultiCompress::Child(int const &FD)
while (1)
{
unsigned long long Res = 0;
- if (CompFd.Read(Buffer,sizeof(Buffer), &Res) == false)
+ if (CompFd.Read(Buffer.data(),Buffer.size(), &Res) == false)
return _error->Errno("read",_("Failed to read while computing MD5"));
if (Res == 0)
break;
NewFileSize += Res;
- OldMD5.Add(Buffer,Res);
+ OldMD5.Add(Buffer.data(),Res);
}
CompFd.Close();
diff --git a/ftparchive/sources.cc b/ftparchive/sources.cc
index a59224395..4c7a51dff 100644
--- a/ftparchive/sources.cc
+++ b/ftparchive/sources.cc
@@ -3,7 +3,7 @@
#include <sstream>
#include <string>
-// for memcpy
+#include <array>
#include <cstring>
#include <apt-pkg/error.h>
@@ -42,16 +42,16 @@ bool DscExtract::Read(std::string FileName)
IsClearSigned = (FileName != F.Name());
std::ostringstream data;
- char buffer[1024];
+ std::array<char, APT_BUFFER_SIZE> buffer;
do {
unsigned long long actual = 0;
- if (F.Read(buffer, sizeof(buffer)-1, &actual) == false)
+ if (F.Read(buffer.data(), buffer.size()-1, &actual) == false)
return _error->Errno("read", "Failed to read dsc file %s", FileName.c_str());
if (actual == 0)
break;
Length += actual;
buffer[actual] = '\0';
- data << buffer;
+ data << buffer.data();
} while(true);
// adding two newlines 'off record' for pkgTagSection.Scan() calls
diff --git a/methods/store.cc b/methods/store.cc
index 8b30efaf3..23d6b43d0 100644
--- a/methods/store.cc
+++ b/methods/store.cc
@@ -21,6 +21,7 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/strutl.h>
+#include <array>
#include <cstring>
#include <string>
#include <vector>
@@ -103,10 +104,10 @@ bool StoreMethod::Fetch(FetchItem *Itm) /*{{{*/
Res.Size = 0;
while (1)
{
- unsigned char Buffer[APT_BUFFER_SIZE];
+ std::array<unsigned char, APT_BUFFER_SIZE> Buffer;
unsigned long long Count = 0;
- if (!From.Read(Buffer,sizeof(Buffer),&Count))
+ if (!From.Read(Buffer.data(),Buffer.size(),&Count))
{
if (To.IsOpen())
To.OpFail();
@@ -116,8 +117,8 @@ bool StoreMethod::Fetch(FetchItem *Itm) /*{{{*/
break;
Res.Size += Count;
- Hash.Add(Buffer,Count);
- if (To.IsOpen() && To.Write(Buffer,Count) == false)
+ Hash.Add(Buffer.data(),Count);
+ if (To.IsOpen() && To.Write(Buffer.data(),Count) == false)
{
Failed = true;
break;
diff --git a/test/integration/framework b/test/integration/framework
index 477aebd39..e054b4209 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -256,7 +256,12 @@ valgrind() {
if [ "${CMD##*/}" = "$CMD" ]; then
CMD="${APTCMDLINEBINDIR}/${CMD}"
fi
- runapt command valgrind -q --error-exitcode=7 "$CMD" "$@"
+ if command -v valgrind > /dev/null; then
+ runapt command valgrind -q --error-exitcode=7 "$CMD" "$@"
+ else
+ msgdebug "Running without valgrind"
+ runapt command "$CMD" "$@"
+ fi
}
lastmodification() {
diff --git a/test/integration/test-apt-update-simple b/test/integration/test-apt-update-simple
index 0d28034aa..6855f1d1f 100755
--- a/test/integration/test-apt-update-simple
+++ b/test/integration/test-apt-update-simple
@@ -34,9 +34,4 @@ main/i18n/Translation-de' aptget indextargets --format '$(METAKEY)'
# Check that -o Acquire::Queue-Mode=access does not crash
find rootdir/var/lib/apt/lists/ -type f -delete
-if [ "$(command dpkg --print-architecture)" = "armhf" ]; then
- msgskip "valgrind on armhf is broken"
- testsuccess aptget update -o Acquire::Queue-Mode=access
-else
- testsuccess valgrind aptget update -o Acquire::Queue-Mode=access
-fi
+testsuccess valgrind aptget update -o Acquire::Queue-Mode=access