From c033d41504957ed04d64ec72e7f47dfac64218b5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 9 Aug 2011 14:50:20 +0200 Subject: * apt-pkg/acquire.cc: - fix potential divide-by-zero --- apt-pkg/acquire.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 2064abc50..06b0f11f8 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -849,7 +849,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) char msg[200]; long i = CurrentItems < TotalItems ? CurrentItems + 1 : CurrentItems; - unsigned long long const ETA = (TotalBytes - CurrentBytes) / CurrentCPS; + unsigned long long ETA = 0; + if(CurrentCPS > 0) + ETA = (TotalBytes - CurrentBytes) / CurrentCPS; // only show the ETA if it makes sense if (ETA > 0 && ETA < 172800 /* two days */ ) -- cgit v1.2.3 From f7f0d6c7560a8f71707e7852a512469147aa9f84 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Aug 2011 20:53:28 +0200 Subject: cppcheck complains about some possible speed improvements which could be done on the mirco-optimazation level, so lets fix them: (performance) Possible inefficient checking for emptiness. (performance) Prefer prefix ++/-- operators for non-primitive types. --- apt-pkg/acquire.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 9478cdfb4..a2da196be 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -116,7 +116,7 @@ pkgAcquire::~pkgAcquire() /* */ void pkgAcquire::Shutdown() { - while (Items.size() != 0) + while (Items.empty() == false) { if (Items[0]->Status == Item::StatFetching) Items[0]->Status = Item::StatError; @@ -155,7 +155,7 @@ void pkgAcquire::Remove(Item *Itm) I = Items.begin(); } else - I++; + ++I; } } /*}}}*/ @@ -411,7 +411,7 @@ pkgAcquire::RunResult pkgAcquire::Run(int PulseIntervall) I->Shutdown(false); // Shut down the items - for (ItemIterator I = Items.begin(); I != Items.end(); I++) + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) (*I)->Finished(); if (_error->PendingError()) @@ -467,7 +467,7 @@ bool pkgAcquire::Clean(string Dir) // Look in the get list ItemCIterator I = Items.begin(); - for (; I != Items.end(); I++) + for (; I != Items.end(); ++I) if (flNotDir((*I)->DestFile) == Dir->d_name) break; @@ -488,7 +488,7 @@ bool pkgAcquire::Clean(string Dir) unsigned long long pkgAcquire::TotalNeeded() { unsigned long long Total = 0; - for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) + for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I) Total += (*I)->FileSize; return Total; } @@ -499,7 +499,7 @@ unsigned long long pkgAcquire::TotalNeeded() unsigned long long pkgAcquire::FetchNeeded() { unsigned long long Total = 0; - for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) + for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I) if ((*I)->Local == false) Total += (*I)->FileSize; return Total; @@ -511,7 +511,7 @@ unsigned long long pkgAcquire::FetchNeeded() unsigned long long pkgAcquire::PartialPresent() { unsigned long long Total = 0; - for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) + for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I) if ((*I)->Local == false) Total += (*I)->PartialSize; return Total; @@ -781,11 +781,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) unsigned int Unknown = 0; unsigned int Count = 0; for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); I != Owner->ItemsEnd(); - I++, Count++) + ++I, ++Count) { TotalItems++; if ((*I)->Status == pkgAcquire::Item::StatDone) - CurrentItems++; + ++CurrentItems; // Totally ignore local items if ((*I)->Local == true) @@ -795,7 +795,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) if ((*I)->Complete == true) CurrentBytes += (*I)->FileSize; if ((*I)->FileSize == 0 && (*I)->Complete == false) - Unknown++; + ++Unknown; } // Compute the current completion -- cgit v1.2.3