Browse Source

avoid some useless casts reported by -Wuseless-cast

The casts are useless, but the reports show some where we can actually
improve the code by replacing them with better alternatives like
converting whatever int type into a string instead of casting to a
specific one which might in the future be too small.

Reported-By: gcc -Wuseless-cast
debian/1.8.y
David Kalnischkies 5 years ago
parent
commit
1adcf56bec
  1. 2
      apt-pkg/cdrom.cc
  2. 33
      apt-pkg/contrib/cdromutl.cc
  3. 15
      apt-pkg/indexcopy.cc
  4. 7
      apt-private/private-source.cc
  5. 2
      cmdline/apt-config.cc
  6. 5
      ftparchive/writer.cc
  7. 2
      methods/basehttp.cc
  8. 2
      test/libapt/getlistoffilesindir_test.cc
  9. 4
      test/libapt/globalerror_test.cc

2
apt-pkg/cdrom.cc

@ -315,7 +315,7 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
c != compressor.end(); ++c)
{
std::string filename = std::string(List[I]).append(Name).append(c->Extension);
std::string const filename = List[I] + Name + c->Extension;
if (stat(filename.c_str(), &Buf) != 0)
continue;
Inodes[I] = Buf.st_ino;

33
apt-pkg/contrib/cdromutl.cc

@ -105,13 +105,14 @@ bool UnmountCdrom(string Path)
}
else
{
const char *Args[10];
Args[0] = "umount";
Args[1] = Path.c_str();
Args[2] = 0;
execvp(Args[0],(char **)Args);
const char * const Args[] = {
"umount",
Path.c_str(),
nullptr
};
execvp(Args[0], const_cast<char **>(Args));
_exit(100);
}
}
}
// if it can not be umounted, give it a bit more time
@ -222,15 +223,13 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
std::string S;
if (Version <= 1)
{
strprintf(S, "%lu", (unsigned long)Dir->d_ino);
}
S = std::to_string(Dir->d_ino);
else
{
struct stat Buf;
if (fstatat(dirfd, Dir->d_name, &Buf, 0) != 0)
continue;
strprintf(S, "%lu", (unsigned long)Buf.st_mtime);
S = std::to_string(Buf.st_mtime);
}
Hash.Add(S.c_str());
@ -246,21 +245,17 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
return _error->Errno("statfs",_("Failed to stat the cdrom"));
// We use a kilobyte block size to avoid overflow
if (writable_media)
{
strprintf(S, "%lu", (unsigned long)(Buf.f_blocks*(Buf.f_bsize/1024)));
} else {
strprintf(S, "%lu %lu", (unsigned long)(Buf.f_blocks*(Buf.f_bsize/1024)),
(unsigned long)(Buf.f_bfree*(Buf.f_bsize/1024)));
}
Hash.Add(S.c_str());
S = std::to_string(Buf.f_blocks * (Buf.f_bsize / 1024));
if (writable_media == false)
S.append(" ").append(std::to_string(Buf.f_bfree * (Buf.f_bsize / 1024)));
Hash.Add(S.c_str(), S.length());
strprintf(S, "-%u", Version);
}
else
strprintf(S, "-%u.debug", Version);
closedir(D);
Res = Hash.Result().Value() + S;
Res = Hash.Result().Value().append(std::move(S));
return true;
}
/*}}}*/

15
apt-pkg/indexcopy.cc

@ -58,15 +58,14 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
// Prepare the progress indicator
off_t TotalSize = 0;
std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
for (auto const &F : List)
{
struct stat Buf;
bool found = false;
std::string file = std::string(*I).append(GetFileName());
for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
c != compressor.end(); ++c)
auto const file = F + GetFileName();
for (auto const &ext: APT::Configuration::getCompressorExtensions())
{
if (stat((file + c->Extension).c_str(), &Buf) != 0)
if (stat((file + ext).c_str(), &Buf) != 0)
continue;
found = true;
break;
@ -82,9 +81,9 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
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());
{
std::string OrigPath(*I,CDROM.length());
// Open the package file
FileFd Pkg(*I + GetFileName(), FileFd::ReadOnly, FileFd::Auto);
off_t const FileSize = Pkg.Size();

7
apt-private/private-source.cc

@ -208,12 +208,7 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
// or RelTag
if (Cache.BuildPolicy() == false)
return nullptr;
pkgPolicy * Policy = dynamic_cast<pkgPolicy*>(Cache.GetPolicy());
if (Policy == nullptr)
{
_error->Fatal("Implementation error: dynamic up-casting policy engine failed in FindSrc!");
return nullptr;
}
pkgPolicy * const Policy = Cache.GetPolicy();
pkgCache::VerIterator const Ver = Policy->GetCandidateVer(Pkg);
if (Ver.end() == false)
{

2
cmdline/apt-config.cc

@ -128,7 +128,7 @@ int main(int argc,const char *argv[]) /*{{{*/
_config->Set(comp + "Name", c->Name);
_config->Set(comp + "Extension", c->Extension);
_config->Set(comp + "Binary", c->Binary);
_config->Set(std::string(comp + "Cost").c_str(), c->Cost);
_config->Set((comp + "Cost").c_str(), c->Cost);
for (std::vector<std::string>::const_iterator a = c->CompressArgs.begin(); a != c->CompressArgs.end(); ++a)
_config->Set(comp + "CompressArg::", *a);
for (std::vector<std::string>::const_iterator a = c->UncompressArgs.begin(); a != c->UncompressArgs.end(); ++a)

5
ftparchive/writer.cc

@ -477,10 +477,7 @@ bool PackagesWriter::DoPackage(string FileName)
// This lists all the changes to the fields we are going to make.
std::vector<pkgTagSection::Tag> Changes;
std::string Size;
strprintf(Size, "%llu", (unsigned long long) FileSize);
Changes.push_back(pkgTagSection::Tag::Rewrite("Size", Size));
Changes.push_back(pkgTagSection::Tag::Rewrite("Size", std::to_string(FileSize)));
for (HashStringList::const_iterator hs = Db.HashesList.begin(); hs != Db.HashesList.end(); ++hs)
{

2
methods/basehttp.cc

@ -191,7 +191,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/
; // we got the expected filesize which is all we wanted
else if (sscanf(Val.c_str(),"bytes %llu-%*u/%llu",&StartPos,&TotalFileSize) != 2)
return _error->Error(_("The HTTP server sent an invalid Content-Range header"));
if ((unsigned long long)StartPos > TotalFileSize)
if (StartPos > TotalFileSize)
return _error->Error(_("This HTTP server has broken range support"));
// figure out what we will download

2
test/libapt/getlistoffilesindir_test.cc

@ -11,7 +11,7 @@
#include "file-helpers.h"
#define P(x) std::string(tempdir).append("/").append(x)
#define P(x) tempdir + "/" + x
TEST(FileUtlTest,GetListOfFilesInDir)
{

4
test/libapt/globalerror_test.cc

@ -111,11 +111,11 @@ TEST(GlobalErrorTest,LongMessage)
longText.append("a");
EXPECT_FALSE(e.Error("%s horrible %s %d times", longText.c_str(), "happened", 2));
EXPECT_TRUE(e.PopMessage(text));
EXPECT_EQ(std::string(longText).append(" horrible happened 2 times"), text);
EXPECT_EQ(longText + " horrible happened 2 times", text);
EXPECT_FALSE(e.Errno("errno", "%s horrible %s %d times", longText.c_str(), "happened", 2));
EXPECT_TRUE(e.PopMessage(text));
EXPECT_EQ(std::string(longText).append(" horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"), text);
EXPECT_EQ(longText + " horrible happened 2 times - errno (0: " + textOfErrnoZero + ")", text);
EXPECT_FALSE(e.Error("%s horrible %s %d times", longText.c_str(), "happened", 2));
std::ostringstream out;

Loading…
Cancel
Save