diff options
| author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2024-11-11 15:23:46 +0100 |
|---|---|---|
| committer | наб <nabijaczleweli@nabijaczleweli.xyz> | 2024-11-11 15:52:43 +0100 |
| commit | e59793e29ecb47c63b72de4f9d1e6d044a0ff6f2 (patch) | |
| tree | 5973246672cedba43849a5291db0f9e749b14713 /ftparchive | |
| parent | df72264891212bc9846649f3f769a1c44fe787bf (diff) | |
Turn char[APT_BUFFER_SIZE] buffers into std::array<char, APT_BUFFER_SIZE>
Diffstat (limited to 'ftparchive')
| -rw-r--r-- | ftparchive/apt-ftparchive.cc | 10 | ||||
| -rw-r--r-- | ftparchive/multicompress.cc | 13 | ||||
| -rw-r--r-- | ftparchive/sources.cc | 8 |
3 files changed, 15 insertions, 16 deletions
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 |
