From e59793e29ecb47c63b72de4f9d1e6d044a0ff6f2 Mon Sep 17 00:00:00 2001 From: наб Date: Mon, 11 Nov 2024 15:23:46 +0100 Subject: Turn char[APT_BUFFER_SIZE] buffers into std::array --- ftparchive/apt-ftparchive.cc | 10 ++++------ ftparchive/multicompress.cc | 13 +++++++------ ftparchive/sources.cc | 8 ++++---- 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'ftparchive') 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 Buf; while (Size != 0) { - unsigned long long ToRead = Size; - if (Size > sizeof(Buf)) - ToRead = sizeof(Buf); + auto ToRead = std::min(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 #include +#include #include #include #include @@ -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 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 #include -// for memcpy +#include #include #include @@ -42,16 +42,16 @@ bool DscExtract::Read(std::string FileName) IsClearSigned = (FileName != F.Name()); std::ostringstream data; - char buffer[1024]; + std::array 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 -- cgit v1.2.3-70-g09d2