Replace C-style casts with C++ ones

This commit is contained in:
Eugene Shalygin
2017-05-29 14:10:31 +02:00
parent e3671050d1
commit 74cecb1b6c
20 changed files with 41 additions and 39 deletions

View File

@@ -41,7 +41,7 @@ InfoHash::InfoHash(const libtorrent::sha1_hash &nativeHash)
, m_nativeHash(nativeHash)
{
char out[(libtorrent::sha1_hash::size * 2) + 1];
libtorrent::to_hex((char const*)&m_nativeHash[0], libtorrent::sha1_hash::size, out);
libtorrent::to_hex(reinterpret_cast<const char*>(&m_nativeHash[0]), libtorrent::sha1_hash::size, out);
m_hashString = QString(out);
}
@@ -51,7 +51,7 @@ InfoHash::InfoHash(const QString &hashString)
{
QByteArray raw = m_hashString.toLatin1();
if (raw.size() == 40)
m_valid = libtorrent::from_hex(raw.constData(), 40, (char*)&m_nativeHash[0]);
m_valid = libtorrent::from_hex(raw.constData(), 40, reinterpret_cast<char*>(&m_nativeHash[0]));
}

View File

@@ -417,7 +417,7 @@ int FilterParserThread::parseP2BFilterFile()
unsigned char version;
if (!stream.readRawData(buf, sizeof(buf))
|| memcmp(buf, "\xFF\xFF\xFF\xFFP2B", 7)
|| !stream.readRawData((char*)&version, sizeof(version))) {
|| !stream.readRawData(reinterpret_cast<char*>(&version), sizeof(version))) {
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
return ruleCount;
}
@@ -428,8 +428,8 @@ int FilterParserThread::parseP2BFilterFile()
std::string name;
while(getlineInStream(stream, name, '\0') && !m_abort) {
if (!stream.readRawData((char*)&start, sizeof(start))
|| !stream.readRawData((char*)&end, sizeof(end))) {
if (!stream.readRawData(reinterpret_cast<char*>(&start), sizeof(start))
|| !stream.readRawData(reinterpret_cast<char*>(&end), sizeof(end))) {
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
return ruleCount;
}
@@ -450,7 +450,7 @@ int FilterParserThread::parseP2BFilterFile()
else if (version == 3) {
qDebug ("p2b version 3");
unsigned int namecount;
if (!stream.readRawData((char*)&namecount, sizeof(namecount))) {
if (!stream.readRawData(reinterpret_cast<char*>(&namecount), sizeof(namecount))) {
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
return ruleCount;
}
@@ -469,7 +469,7 @@ int FilterParserThread::parseP2BFilterFile()
// Reading the ranges
unsigned int rangecount;
if (!stream.readRawData((char*)&rangecount, sizeof(rangecount))) {
if (!stream.readRawData(reinterpret_cast<char*>(&rangecount), sizeof(rangecount))) {
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
return ruleCount;
}
@@ -477,9 +477,9 @@ int FilterParserThread::parseP2BFilterFile()
rangecount = ntohl(rangecount);
unsigned int name, start, end;
for (unsigned int i = 0; i < rangecount; ++i) {
if (!stream.readRawData((char*)&name, sizeof(name))
|| !stream.readRawData((char*)&start, sizeof(start))
|| !stream.readRawData((char*)&end, sizeof(end))) {
if (!stream.readRawData(reinterpret_cast<char*>(&name), sizeof(name))
|| !stream.readRawData(reinterpret_cast<char*>(&start), sizeof(start))
|| !stream.readRawData(reinterpret_cast<char*>(&end), sizeof(end))) {
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
return ruleCount;
}

View File

@@ -555,7 +555,7 @@ qreal TorrentHandle::progress() const
if (m_nativeStatus.total_wanted_done == m_nativeStatus.total_wanted)
return 1.;
float progress = (float) m_nativeStatus.total_wanted_done / (float) m_nativeStatus.total_wanted;
float progress = static_cast<float>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
Q_ASSERT((progress >= 0.f) && (progress <= 1.f));
return progress;
}

View File

@@ -224,7 +224,9 @@ bool FileSystemWatcher::isNetworkFileSystem(QString path)
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
return ((strcmp(buf.f_fstypename, "nfs") == 0) || (strcmp(buf.f_fstypename, "cifs") == 0) || (strcmp(buf.f_fstypename, "smbfs") == 0));
#else
return ((buf.f_type == (long)CIFS_MAGIC_NUMBER) || (buf.f_type == (long)NFS_SUPER_MAGIC) || (buf.f_type == (long)SMB_SUPER_MAGIC));
return ((buf.f_type == static_cast<long>(CIFS_MAGIC_NUMBER))
|| (buf.f_type == static_cast<long>(NFS_SUPER_MAGIC))
|| (buf.f_type == static_cast<long>(SMB_SUPER_MAGIC)));
#endif
}
else {

View File

@@ -105,7 +105,7 @@ GeoIPDatabase *GeoIPDatabase::load(const QString &filename, QString &error)
db = new GeoIPDatabase(file.size());
if (file.read((char *)db->m_data, db->m_size) != db->m_size) {
if (file.read(reinterpret_cast<char *>(db->m_data), db->m_size) != db->m_size) {
error = file.errorString();
delete db;
return 0;
@@ -130,7 +130,7 @@ GeoIPDatabase *GeoIPDatabase::load(const QByteArray &data, QString &error)
db = new GeoIPDatabase(data.size());
memcpy((char *)db->m_data, data.constData(), db->m_size);
memcpy(reinterpret_cast<char *>(db->m_data), data.constData(), db->m_size);
if (!db->parseMetadata(db->readMetadata(), error) || !db->loadDB(error)) {
delete db;

View File

@@ -406,12 +406,12 @@ void Preferences::setSchedulerEndTime(const QTime &time)
scheduler_days Preferences::getSchedulerDays() const
{
return (scheduler_days)value("Preferences/Scheduler/days", EVERY_DAY).toInt();
return static_cast<scheduler_days>(value("Preferences/Scheduler/days", EVERY_DAY).toInt());
}
void Preferences::setSchedulerDays(scheduler_days days)
{
setValue("Preferences/Scheduler/days", (int)days);
setValue("Preferences/Scheduler/days", static_cast<int>(days));
}
// Search

View File

@@ -56,7 +56,7 @@ uint32_t Utils::Random::rand(const uint32_t min, const uint32_t max)
static thread_local std::mt19937 generator{
hasTrueRandomDevice
? std::random_device{}()
: (std::random_device::result_type) std::chrono::system_clock::now().time_since_epoch().count()
: static_cast<std::random_device::result_type>(std::chrono::system_clock::now().time_since_epoch().count())
};
#endif