summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-05-02 18:25:58 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2016-05-20 14:18:36 +0200
commita6f8c07f83e4e5a8155c04feab543dc0c82ed495 (patch)
treec4430a4fe7d31e618cc46fde90c1e992d5617b92
parentaf859f09084b4f6163501f216ba8cc2356fb3f93 (diff)
avoid triggering gcc's -Wunsafe-loop-optimizations in EDSP
apt/apt-pkg/edsp.cc: In function ‘bool EDSP::WriteLimitedScenario(pkgDepCache&, FILE*, const PackageSet&, OpProgress*)’: apt/apt-pkg/edsp.cc:245:56: warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations] std::string dependencies[pkgCache::Dep::Enhances + 1]; ^ Using a std::array to silence gcc as well as as a code improvement feels right here. Git-Dch: Ignore
-rw-r--r--apt-pkg/edsp.cc33
1 files changed, 19 insertions, 14 deletions
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc
index 9add554dd..9596a9eb3 100644
--- a/apt-pkg/edsp.cc
+++ b/apt-pkg/edsp.cc
@@ -23,7 +23,8 @@
#include <string.h>
#include <unistd.h>
#include <stdio.h>
-#include <iostream>
+
+#include <array>
#include <limits>
#include <string>
@@ -33,11 +34,15 @@
using std::string;
// we could use pkgCache::DepType and ::Priority, but these would be localized strings…
-const char * const PrioMap[] = {0, "important", "required", "standard",
- "optional", "extra"};
-const char * const DepMap[] = {"", "Depends", "Pre-Depends", "Suggests",
- "Recommends" , "Conflicts", "Replaces",
- "Obsoletes", "Breaks", "Enhances"};
+constexpr char const * const PrioMap[] = {
+ nullptr, "important", "required", "standard",
+ "optional", "extra"
+};
+constexpr char const * const DepMap[] = {
+ nullptr, "Depends", "Pre-Depends", "Suggests",
+ "Recommends" , "Conflicts", "Replaces",
+ "Obsoletes", "Breaks", "Enhances"
+};
// WriteOkay - varaidic helper to easily Write to a FileFd /*{{{*/
static bool WriteOkay_fn(FileFd &) { return true; }
@@ -160,7 +165,7 @@ static bool WriteScenarioVersion(pkgDepCache &Cache, FileFd &output, pkgCache::P
// WriteScenarioDependency /*{{{*/
static void WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &Ver)
{
- std::string dependencies[pkgCache::Dep::Enhances + 1];
+ std::array<std::string, _count(DepMap)> dependencies;
bool orGroup = false;
for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
{
@@ -179,7 +184,7 @@ static void WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &
else
orGroup = false;
}
- for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+ for (size_t i = 1; i < dependencies.size(); ++i)
if (dependencies[i].empty() == false)
fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2);
string provides;
@@ -198,7 +203,7 @@ static void WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &
}
static bool WriteScenarioDependency(FileFd &output, pkgCache::VerIterator const &Ver)
{
- std::string dependencies[pkgCache::Dep::Enhances + 1];
+ std::array<std::string, _count(DepMap)> dependencies;
bool orGroup = false;
for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
{
@@ -218,7 +223,7 @@ static bool WriteScenarioDependency(FileFd &output, pkgCache::VerIterator const
orGroup = false;
}
bool Okay = output.Failed() == false;
- for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+ for (size_t i = 1; i < dependencies.size(); ++i)
if (dependencies[i].empty() == false)
WriteOkay(Okay, output, "\n", DepMap[i], ": ", dependencies[i]);
string provides;
@@ -242,7 +247,7 @@ static void WriteScenarioLimitedDependency(FILE* output,
pkgCache::VerIterator const &Ver,
APT::PackageSet const &pkgset)
{
- std::string dependencies[pkgCache::Dep::Enhances + 1];
+ std::array<std::string, _count(DepMap)> dependencies;
bool orGroup = false;
for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
{
@@ -274,7 +279,7 @@ static void WriteScenarioLimitedDependency(FILE* output,
else
orGroup = false;
}
- for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+ for (size_t i = 1; i < dependencies.size(); ++i)
if (dependencies[i].empty() == false)
fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str());
string provides;
@@ -297,7 +302,7 @@ static bool WriteScenarioLimitedDependency(FileFd &output,
pkgCache::VerIterator const &Ver,
APT::PackageSet const &pkgset)
{
- std::string dependencies[pkgCache::Dep::Enhances + 1];
+ std::array<std::string, _count(DepMap)> dependencies;
bool orGroup = false;
for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
{
@@ -330,7 +335,7 @@ static bool WriteScenarioLimitedDependency(FileFd &output,
orGroup = false;
}
bool Okay = output.Failed() == false;
- for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+ for (size_t i = 1; i < dependencies.size(); ++i)
if (dependencies[i].empty() == false)
WriteOkay(Okay, output, "\n", DepMap[i], ": ", dependencies[i]);
string provides;