summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/cdromutl.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2017-12-13 21:39:16 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2017-12-13 23:53:41 +0100
commit1adcf56bec7d2127d83aa423916639740fe8e586 (patch)
tree39802989990796e903d8e670b07408380b117c21 /apt-pkg/contrib/cdromutl.cc
parent957381a0d26ec11a172ebfc64f892d1b31f0c193 (diff)
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
Diffstat (limited to 'apt-pkg/contrib/cdromutl.cc')
-rw-r--r--apt-pkg/contrib/cdromutl.cc33
1 files changed, 14 insertions, 19 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 93bfb9f42..7ae54060a 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/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;
}
/*}}}*/