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 --- apt-pkg/contrib/hashes.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'apt-pkg/contrib/hashes.cc') 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 #include +#include #include #include #include @@ -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 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 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; -- cgit v1.2.3-70-g09d2