summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2013-03-10 12:24:13 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2013-03-10 12:24:13 +0100
commit69c2ecbdc937e3c73fe67d3c9bce12a80d3ec7ec (patch)
treeb3b8f0753ebe2760ab8d97b0e9404ddbeef25a1b
parentfd6a8d0ddc14406bb6c0996b5bbaa95d6ccc1186 (diff)
various simple changes to fix cppcheck warnings
-rw-r--r--apt-inst/extract.cc3
-rw-r--r--apt-pkg/acquire-item.cc4
-rw-r--r--apt-pkg/aptconfiguration.cc2
-rw-r--r--apt-pkg/cachefilter.cc3
-rw-r--r--apt-pkg/contrib/configuration.cc2
-rw-r--r--apt-pkg/contrib/fileutl.cc10
-rw-r--r--apt-pkg/contrib/netrc.cc8
-rw-r--r--apt-pkg/contrib/strutl.cc8
-rw-r--r--apt-pkg/deb/dpkgpm.cc17
-rw-r--r--apt-pkg/indexcopy.cc6
-rw-r--r--apt-pkg/orderlist.cc4
-rw-r--r--apt-pkg/pkgcache.cc18
-rw-r--r--apt-pkg/srcrecords.cc11
-rw-r--r--apt-pkg/vendor.cc2
-rw-r--r--apt-pkg/versionmatch.cc2
-rw-r--r--cmdline/apt-get.cc4
-rw-r--r--debian/changelog7
-rw-r--r--methods/rfc2553emu.cc2
18 files changed, 55 insertions, 58 deletions
diff --git a/apt-inst/extract.cc b/apt-inst/extract.cc
index 29e163028..2c95fba92 100644
--- a/apt-inst/extract.cc
+++ b/apt-inst/extract.cc
@@ -81,8 +81,6 @@ pkgExtract::pkgExtract(pkgFLCache &FLCache,pkgCache::VerIterator Ver) :
/* This performs the setup for the extraction.. */
bool pkgExtract::DoItem(Item &Itm,int &Fd)
{
- char Temp[sizeof(FileName)];
-
/* Strip any leading/trailing /s from the filename, then copy it to the
temp buffer and re-apply the leading / We use a class variable
to store the new filename for use by the three extraction funcs */
@@ -183,6 +181,7 @@ bool pkgExtract::DoItem(Item &Itm,int &Fd)
// See if we can recover the backup file
if (Nde.end() == false)
{
+ char Temp[sizeof(FileName)];
snprintf(Temp,sizeof(Temp),"%s.%s",Itm.Name,TempExt);
if (rename(Temp,Itm.Name) != 0 && errno != ENOENT)
return _error->Errno("rename",_("Failed to rename %s to %s"),
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index a71886a87..6ad10e26e 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -560,7 +560,7 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner,
Desc.Owner = this;
Desc.ShortDesc = ShortDesc;
- if(available_patches.size() == 0)
+ if(available_patches.empty() == true)
{
// we are done (yeah!)
Finish(true);
@@ -1643,7 +1643,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
assumption here that all the available sources for this version share
the same extension.. */
// Skip not source sources, they do not have file fields.
- for (; Vf.end() == false; Vf++)
+ for (; Vf.end() == false; ++Vf)
{
if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
continue;
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 653775688..37c846582 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -401,8 +401,8 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
close(external[1]);
FILE *dpkg = fdopen(external[0], "r");
- char buf[1024];
if(dpkg != NULL) {
+ char buf[1024];
while (fgets(buf, sizeof(buf), dpkg) != NULL) {
char* arch = strtok(buf, " ");
while (arch != NULL) {
diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc
index 58cc812bf..64cde41d1 100644
--- a/apt-pkg/cachefilter.cc
+++ b/apt-pkg/cachefilter.cc
@@ -71,8 +71,7 @@ static std::string CompleteArch(std::string const &arch) {
}
/*}}}*/
PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/
- literal(pattern), isPattern(isPattern), d(NULL) {
- complete = CompleteArch(pattern);
+ literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern), d(NULL) {
}
/*}}}*/
bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 4de17e3e1..808a708a1 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -958,7 +958,7 @@ Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config)
continue;
}
}
- if (strings.size() == 0)
+ if (strings.empty() == true)
patterns.push_back(NULL);
}
/*}}}*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 90e49cbfa..f18e17005 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -387,7 +387,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
std::vector<string> List;
- if (DirectoryExists(Dir.c_str()) == false)
+ if (DirectoryExists(Dir) == false)
{
_error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str());
return List;
@@ -413,14 +413,14 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
if (Ent->d_type != DT_REG)
#endif
{
- if (RealFileExists(File.c_str()) == false)
+ if (RealFileExists(File) == false)
{
// do not show ignoration warnings for directories
if (
#ifdef _DIRENT_HAVE_D_TYPE
Ent->d_type == DT_DIR ||
#endif
- DirectoryExists(File.c_str()) == true)
+ DirectoryExists(File) == true)
continue;
if (SilentIgnore.Match(Ent->d_name) == false)
_error->Notice(_("Ignoring '%s' in directory '%s' as it is not a regular file"), Ent->d_name, Dir.c_str());
@@ -501,7 +501,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, bool SortList)
std::vector<string> List;
- if (DirectoryExists(Dir.c_str()) == false)
+ if (DirectoryExists(Dir) == false)
{
_error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str());
return List;
@@ -526,7 +526,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, bool SortList)
if (Ent->d_type != DT_REG)
#endif
{
- if (RealFileExists(File.c_str()) == false)
+ if (RealFileExists(File) == false)
{
if (Debug == true)
std::clog << "Bad file: " << Ent->d_name << " → it is not a real file" << std::endl;
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index 0a902f126..de95aa4ab 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -50,14 +50,10 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
FILE *file;
int retcode = 1;
int specific_login = (login.empty() == false);
- char *home = NULL;
bool netrc_alloc = false;
- int state_our_login = false; /* With specific_login,
- found *our* login name */
-
if (!netrcfile) {
- home = getenv ("HOME"); /* portable environment reader */
+ char const * home = getenv ("HOME"); /* portable environment reader */
if (!home) {
struct passwd *pw;
@@ -86,6 +82,8 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
int state = NOTHING;
char state_login = 0; /* Found a login keyword */
char state_password = 0; /* Found a password keyword */
+ int state_our_login = false; /* With specific_login,
+ found *our* login name */
while (!done && getline(&netrcbuffer, &netrcbuffer_size, file) != -1) {
tok = strtok_r (netrcbuffer, " \t\n", &tok_buf);
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index ca096d736..f643db451 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1246,7 +1246,7 @@ string StripEpoch(const string &VerStr)
return VerStr;
return VerStr.substr(i+1);
}
-
+ /*}}}*/
// tolower_ascii - tolower() function that ignores the locale /*{{{*/
// ---------------------------------------------------------------------
/* This little function is the most called method we have and tries
@@ -1284,14 +1284,14 @@ bool CheckDomainList(const string &Host,const string &List)
return false;
}
/*}}}*/
-// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/
+// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/
// ---------------------------------------------------------------------
/* */
string DeEscapeString(const string &input)
{
char tmp[3];
- string::const_iterator it, escape_start;
- string output, octal, hex;
+ string::const_iterator it;
+ string output;
for (it = input.begin(); it != input.end(); ++it)
{
// just copy non-escape chars
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 6cb8bc6b6..3bc31dc37 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -147,11 +147,11 @@ static
pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg)
{
pkgCache::VerIterator Ver;
- for (Ver = Pkg.VersionList(); Ver.end() == false; Ver++)
+ for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
{
pkgCache::VerFileIterator Vf = Ver.FileList();
pkgCache::PkgFileIterator F = Vf.File();
- for (F = Vf.File(); F.end() == false; F++)
+ for (F = Vf.File(); F.end() == false; ++F)
{
if (F && F.Archive())
{
@@ -1585,12 +1585,12 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
if (!logfile_name.empty())
{
FILE *log = NULL;
- char buf[1024];
fprintf(report, "DpkgTerminalLog:\n");
log = fopen(logfile_name.c_str(),"r");
if(log != NULL)
{
+ char buf[1024];
while( fgets(buf, sizeof(buf), log) != NULL)
fprintf(report, " %s", buf);
fclose(log);
@@ -1609,13 +1609,11 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
// attach dmesg log (to learn about segfaults)
if (FileExists("/bin/dmesg"))
{
- FILE *log = NULL;
- char buf[1024];
-
fprintf(report, "Dmesg:\n");
- log = popen("/bin/dmesg","r");
+ FILE *log = popen("/bin/dmesg","r");
if(log != NULL)
{
+ char buf[1024];
while( fgets(buf, sizeof(buf), log) != NULL)
fprintf(report, " %s", buf);
pclose(log);
@@ -1625,13 +1623,12 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
// attach df -l log (to learn about filesystem status)
if (FileExists("/bin/df"))
{
- FILE *log = NULL;
- char buf[1024];
fprintf(report, "Df:\n");
- log = popen("/bin/df -l","r");
+ FILE *log = popen("/bin/df -l","r");
if(log != NULL)
{
+ char buf[1024];
while( fgets(buf, sizeof(buf), log) != NULL)
fprintf(report, " %s", buf);
pclose(log);
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc
index aa1f01a4a..6e35fc40e 100644
--- a/apt-pkg/indexcopy.cc
+++ b/apt-pkg/indexcopy.cc
@@ -141,7 +141,6 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
File = OrigPath + ChopDirs(File,Chop);
// See if the file exists
- bool Mangled = false;
if (NoStat == false || Hits < 10)
{
// Attempt to fix broken structure
@@ -164,6 +163,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
if (stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0 ||
Buf.st_size == 0)
{
+ bool Mangled = false;
// Attempt to fix busted symlink support for one instance
string OrigFile = File;
string::size_type Start = File.find("binary-");
@@ -799,9 +799,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/
unsigned int WrongSize = 0;
unsigned int Packages = 0;
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
- {
- string OrigPath = string(*I,CDROM.length());
-
+ {
// Open the package file
FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Auto);
off_t const FileSize = Pkg.Size();
diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc
index 3a179b2a2..80d8fd490 100644
--- a/apt-pkg/orderlist.cc
+++ b/apt-pkg/orderlist.cc
@@ -331,9 +331,11 @@ int pkgOrderList::Score(PkgIterator Pkg)
}
// Important Required Standard Optional Extra
- signed short PrioMap[] = {0,5,4,3,1,0};
if (Cache[Pkg].InstVerIter(Cache)->Priority <= 5)
+ {
+ signed short PrioMap[] = {0,5,4,3,1,0};
Score += PrioMap[Cache[Pkg].InstVerIter(Cache)->Priority];
+ }
return Score;
}
/*}}}*/
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index 1de33ff9b..1378876fe 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -279,22 +279,22 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) {
type in the weird debian style.. */
const char *pkgCache::CompTypeDeb(unsigned char Comp)
{
- const char *Ops[] = {"","<=",">=","<<",">>","=","!="};
- if ((unsigned)(Comp & 0xF) < 7)
- return Ops[Comp & 0xF];
- return "";
+ const char * const Ops[] = {"","<=",">=","<<",">>","=","!="};
+ if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0])))
+ return "";
+ return Ops[Comp & 0xF];
}
/*}}}*/
// Cache::CompType - Return a string describing the compare type /*{{{*/
// ---------------------------------------------------------------------
-/* This returns a string representation of the dependency compare
+/* This returns a string representation of the dependency compare
type */
const char *pkgCache::CompType(unsigned char Comp)
{
- const char *Ops[] = {"","<=",">=","<",">","=","!="};
- if ((unsigned)(Comp & 0xF) < 7)
- return Ops[Comp & 0xF];
- return "";
+ const char * const Ops[] = {"","<=",">=","<",">","=","!="};
+ if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0])))
+ return "";
+ return Ops[Comp & 0xF];
}
/*}}}*/
// Cache::DepType - Return a string describing the dep type /*{{{*/
diff --git a/apt-pkg/srcrecords.cc b/apt-pkg/srcrecords.cc
index d63d2c422..297559957 100644
--- a/apt-pkg/srcrecords.cc
+++ b/apt-pkg/srcrecords.cc
@@ -42,7 +42,7 @@ pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0), Current(0
}
// Doesn't work without any source index files
- if (Files.size() == 0)
+ if (Files.empty() == true)
{
_error->Error(_("You must put some 'source' URIs"
" in your sources.list"));
@@ -121,14 +121,13 @@ pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOn
/* */
const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type)
{
- const char *fields[] = {"Build-Depends",
- "Build-Depends-Indep",
+ const char *fields[] = {"Build-Depends",
+ "Build-Depends-Indep",
"Build-Conflicts",
"Build-Conflicts-Indep"};
- if (Type < 4)
- return fields[Type];
- else
+ if (unlikely(Type >= sizeof(fields)/sizeof(fields[0])))
return "";
+ return fields[Type];
}
/*}}}*/
diff --git a/apt-pkg/vendor.cc b/apt-pkg/vendor.cc
index 36fc25957..fc03ec845 100644
--- a/apt-pkg/vendor.cc
+++ b/apt-pkg/vendor.cc
@@ -12,7 +12,7 @@ Vendor::Vendor(std::string VendorID,
this->VendorID = VendorID;
this->Origin = Origin;
for (std::vector<struct Vendor::Fingerprint *>::iterator I = FingerprintList->begin();
- I != FingerprintList->end(); I++)
+ I != FingerprintList->end(); ++I)
{
if (_config->FindB("Debug::Vendor", false))
std::cerr << "Vendor \"" << VendorID << "\": Mapping \""
diff --git a/apt-pkg/versionmatch.cc b/apt-pkg/versionmatch.cc
index e4fa0ea65..26262a010 100644
--- a/apt-pkg/versionmatch.cc
+++ b/apt-pkg/versionmatch.cc
@@ -181,9 +181,9 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg)
bool pkgVersionMatch::ExpressionMatches(const char *pattern, const char *string)
{
if (pattern[0] == '/') {
- bool res = false;
size_t length = strlen(pattern);
if (pattern[length - 1] == '/') {
+ bool res = false;
regex_t preg;
char *regex = strdup(pattern + 1);
regex[length - 2] = '\0';
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index e3c74a099..5e6f50d41 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -1912,7 +1912,6 @@ bool DoInstall(CommandLine &CmdL)
return false;
}
- unsigned short const order[] = { MOD_REMOVE, MOD_INSTALL, 0 };
TryToInstall InstallAction(Cache, Fix, BrokenFix);
TryToRemove RemoveAction(Cache, Fix);
@@ -1920,6 +1919,7 @@ bool DoInstall(CommandLine &CmdL)
// new scope for the ActionGroup
{
pkgDepCache::ActionGroup group(Cache);
+ unsigned short const order[] = { MOD_REMOVE, MOD_INSTALL, 0 };
for (unsigned short i = 0; order[i] != 0; ++i)
{
@@ -2023,7 +2023,7 @@ bool DoInstall(CommandLine &CmdL)
/* Print out a list of suggested and recommended packages */
{
- string SuggestsList, RecommendsList, List;
+ string SuggestsList, RecommendsList;
string SuggestsVersions, RecommendsVersions;
for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
{
diff --git a/debian/changelog b/debian/changelog
index bfc4279b3..067103c72 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+apt (0.9.7.8~exp2+nmu1) UNRELEASED; urgency=low
+
+ [ David Kalnischkies ]
+ * various simple changes to fix cppcheck warnings
+
+ -- David Kalnischkies <kalnischkies@gmail.com> Sun, 10 Mar 2013 12:23:24 +0100
+
apt (0.9.7.8~exp2) experimental; urgency=low
* include two missing patches to really fix bug #696225, thanks to
diff --git a/methods/rfc2553emu.cc b/methods/rfc2553emu.cc
index f00e85889..372882769 100644
--- a/methods/rfc2553emu.cc
+++ b/methods/rfc2553emu.cc
@@ -154,11 +154,9 @@ int getaddrinfo(const char *nodename, const char *servname,
/* */
void freeaddrinfo(struct addrinfo *ai)
{
- struct addrinfo *Tmp;
while (ai != 0)
{
free(ai->ai_addr);
- Tmp = ai;
ai = ai->ai_next;
free(ai);
}