Browse Source

various simple changes to fix cppcheck warnings

David Kalnischkies 11 years ago
parent
commit
69c2ecbdc9

+ 1 - 2
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"),

+ 2 - 2
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;

+ 1 - 1
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) {

+ 1 - 2
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) {/*{{{*/

+ 1 - 1
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);
 }
 									/*}}}*/

+ 5 - 5
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;

+ 3 - 5
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);

+ 4 - 4
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

+ 7 - 10
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);

+ 2 - 4
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();

+ 3 - 1
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;
 }
 									/*}}}*/

+ 9 - 9
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		/*{{{*/

+ 5 - 6
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];
 }
 									/*}}}*/
 

+ 1 - 1
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 \""

+ 1 - 1
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';

+ 2 - 2
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++)
       {

+ 7 - 0
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

+ 0 - 2
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);
    }