summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/hashes.cc
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2024-11-11 15:23:46 +0100
committerнаб <nabijaczleweli@nabijaczleweli.xyz>2024-11-11 15:52:43 +0100
commite59793e29ecb47c63b72de4f9d1e6d044a0ff6f2 (patch)
tree5973246672cedba43849a5291db0f9e749b14713 /apt-pkg/contrib/hashes.cc
parentdf72264891212bc9846649f3f769a1c44fe787bf (diff)
Turn char[APT_BUFFER_SIZE] buffers into std::array<char, APT_BUFFER_SIZE>
Diffstat (limited to 'apt-pkg/contrib/hashes.cc')
-rw-r--r--apt-pkg/contrib/hashes.cc17
1 files changed, 9 insertions, 8 deletions
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;