From 5a97834817dd43b7833881f38f512a9f2fdac8a9 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 7 Dec 2015 14:42:25 +0100 Subject: Avoid overflow when summing up file sizes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to pass 0llu instead of 0 as the init value, otherwise std::accumulate will calculate with ints. Reported-by: Raphaƫl Hertzog --- apt-pkg/acquire.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index b229a61b6..cb8741603 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -730,7 +730,7 @@ bool pkgAcquire::Clean(string Dir) /* This is the total number of bytes needed */ APT_PURE unsigned long long pkgAcquire::TotalNeeded() { - return std::accumulate(ItemsBegin(), ItemsEnd(), 0, + return std::accumulate(ItemsBegin(), ItemsEnd(), 0ull, [](unsigned long long const T, Item const * const I) { return T + I->FileSize; }); @@ -741,7 +741,7 @@ APT_PURE unsigned long long pkgAcquire::TotalNeeded() /* This is the number of bytes that is not local */ APT_PURE unsigned long long pkgAcquire::FetchNeeded() { - return std::accumulate(ItemsBegin(), ItemsEnd(), 0, + return std::accumulate(ItemsBegin(), ItemsEnd(), 0llu, [](unsigned long long const T, Item const * const I) { if (I->Local == false) return T + I->FileSize; @@ -755,7 +755,7 @@ APT_PURE unsigned long long pkgAcquire::FetchNeeded() /* This is the number of bytes that is not local */ APT_PURE unsigned long long pkgAcquire::PartialPresent() { - return std::accumulate(ItemsBegin(), ItemsEnd(), 0, + return std::accumulate(ItemsBegin(), ItemsEnd(), 0llu, [](unsigned long long const T, Item const * const I) { if (I->Local == false) return T + I->PartialSize; -- cgit v1.2.3