Merge pull request #10296 from thalieht/clang-tidy

Some suggestions from Clang-tidy
This commit is contained in:
Mike Tzou
2019-02-21 23:17:29 +08:00
committed by GitHub
66 changed files with 283 additions and 304 deletions

View File

@@ -177,9 +177,8 @@ int FilterParserThread::parseDATFilterFile()
memmove(buffer.data(), buffer.data() + start, offset);
break;
}
else {
++nbLine;
}
++nbLine;
if ((buffer[start] == '#')
|| ((buffer[start] == '/') && ((start + 1 < dataSize) && (buffer[start + 1] == '/')))) {
@@ -325,9 +324,8 @@ int FilterParserThread::parseP2PFilterFile()
memmove(buffer.data(), buffer.data() + start, offset);
break;
}
else {
++nbLine;
}
++nbLine;
if ((buffer[start] == '#')
|| ((buffer[start] == '/') && ((start + 1 < dataSize) && (buffer[start + 1] == '/')))) {

View File

@@ -47,10 +47,10 @@ void SpeedMonitor::addSample(const SpeedSample &sample)
SpeedSampleAvg SpeedMonitor::average() const
{
if (m_speedSamples.empty())
return SpeedSampleAvg();
return {};
const qreal k = qreal(1.) / m_speedSamples.size();
return SpeedSampleAvg(m_sum.download * k, m_sum.upload * k);
return {m_sum.download * k, m_sum.upload * k};
}
void SpeedMonitor::reset()

View File

@@ -30,15 +30,12 @@
#include <QDateTime>
#include <libtorrent/session.hpp>
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/profile.h"
static const qint64 SAVE_INTERVAL = 15 * 60 * 1000;
namespace libt = libtorrent;
using namespace BitTorrent;
Statistics::Statistics(Session *session)

View File

@@ -4299,11 +4299,11 @@ namespace
using PCONVERTIFACENAMETOLUID = NETIO_STATUS (WINAPI *)(const WCHAR *, PNET_LUID);
const auto ConvertIfaceNameToLuid = Utils::Misc::loadWinAPI<PCONVERTIFACENAMETOLUID>("Iphlpapi.dll", "ConvertInterfaceNameToLuidW");
if (!ConvertIfaceNameToLuid) return QString();
if (!ConvertIfaceNameToLuid) return {};
using PCONVERTIFACELUIDTOGUID = NETIO_STATUS (WINAPI *)(const NET_LUID *, GUID *);
const auto ConvertIfaceLuidToGuid = Utils::Misc::loadWinAPI<PCONVERTIFACELUIDTOGUID>("Iphlpapi.dll", "ConvertInterfaceLuidToGuid");
if (!ConvertIfaceLuidToGuid) return QString();
if (!ConvertIfaceLuidToGuid) return {};
NET_LUID luid;
const LONG res = ConvertIfaceNameToLuid(name.toStdWString().c_str(), &luid);
@@ -4313,7 +4313,7 @@ namespace
return QUuid(guid).toString().toUpper();
}
return QString();
return {};
}
#endif
}

View File

@@ -297,7 +297,7 @@ QString TorrentHandle::savePath(bool actual) const
QString TorrentHandle::rootPath(bool actual) const
{
if ((filesCount() > 1) && !hasRootFolder())
return QString();
return {};
const QString firstFilePath = filePath(0);
const int slashIndex = firstFilePath.indexOf('/');
@@ -593,7 +593,7 @@ QString TorrentHandle::filePath(int index) const
QString TorrentHandle::fileName(int index) const
{
if (!hasMetadata()) return QString();
if (!hasMetadata()) return {};
return Utils::Fs::fileName(filePath(index));
}
@@ -606,7 +606,7 @@ qlonglong TorrentHandle::fileSize(int index) const
// to all files in a torrent
QStringList TorrentHandle::absoluteFilePaths() const
{
if (!hasMetadata()) return QStringList();
if (!hasMetadata()) return {};
const QDir saveDir(savePath(true));
QStringList res;
@@ -617,7 +617,7 @@ QStringList TorrentHandle::absoluteFilePaths() const
QStringList TorrentHandle::absoluteFilePathsUnwanted() const
{
if (!hasMetadata()) return QStringList();
if (!hasMetadata()) return {};
const QDir saveDir(savePath(true));
QStringList res;
@@ -987,7 +987,7 @@ QDateTime TorrentHandle::lastSeenComplete() const
if (m_nativeStatus.last_seen_complete > 0)
return QDateTime::fromTime_t(m_nativeStatus.last_seen_complete);
else
return QDateTime();
return {};
}
QDateTime TorrentHandle::completedTime() const
@@ -995,7 +995,7 @@ QDateTime TorrentHandle::completedTime() const
if (m_nativeStatus.completed_time > 0)
return QDateTime::fromTime_t(m_nativeStatus.completed_time);
else
return QDateTime();
return {};
}
int TorrentHandle::timeSinceUpload() const

View File

@@ -133,32 +133,32 @@ bool TorrentInfo::isValid() const
InfoHash TorrentInfo::hash() const
{
if (!isValid()) return InfoHash();
if (!isValid()) return {};
return m_nativeInfo->info_hash();
}
QString TorrentInfo::name() const
{
if (!isValid()) return QString();
if (!isValid()) return {};
return QString::fromStdString(m_nativeInfo->name());
}
QDateTime TorrentInfo::creationDate() const
{
if (!isValid()) return QDateTime();
if (!isValid()) return {};
const boost::optional<time_t> t = m_nativeInfo->creation_date();
return t ? QDateTime::fromTime_t(*t) : QDateTime();
}
QString TorrentInfo::creator() const
{
if (!isValid()) return QString();
if (!isValid()) return {};
return QString::fromStdString(m_nativeInfo->creator());
}
QString TorrentInfo::comment() const
{
if (!isValid()) return QString();
if (!isValid()) return {};
return QString::fromStdString(m_nativeInfo->comment());
}
@@ -200,7 +200,7 @@ int TorrentInfo::piecesCount() const
QString TorrentInfo::filePath(const int index) const
{
if (!isValid()) return QString();
if (!isValid()) return {};
return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->files().file_path(index)));
}
@@ -220,7 +220,7 @@ QString TorrentInfo::fileName(const int index) const
QString TorrentInfo::origFilePath(const int index) const
{
if (!isValid()) return QString();
if (!isValid()) return {};
return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->orig_files().file_path(index)));
}
@@ -238,7 +238,7 @@ qlonglong TorrentInfo::fileOffset(const int index) const
QList<TrackerEntry> TorrentInfo::trackers() const
{
if (!isValid()) return QList<TrackerEntry>();
if (!isValid()) return {};
QList<TrackerEntry> trackers;
for (const libt::announce_entry &tracker : m_nativeInfo->trackers())
@@ -249,7 +249,7 @@ QList<TrackerEntry> TorrentInfo::trackers() const
QList<QUrl> TorrentInfo::urlSeeds() const
{
if (!isValid()) return QList<QUrl>();
if (!isValid()) return {};
QList<QUrl> urlSeeds;
for (const libt::web_seed_entry &webSeed : m_nativeInfo->web_seeds())
@@ -261,8 +261,8 @@ QList<QUrl> TorrentInfo::urlSeeds() const
QByteArray TorrentInfo::metadata() const
{
if (!isValid()) return QByteArray();
return QByteArray(m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size());
if (!isValid()) return {};
return {m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()};
}
QStringList TorrentInfo::filesForPiece(const int pieceIndex) const
@@ -281,7 +281,7 @@ QStringList TorrentInfo::filesForPiece(const int pieceIndex) const
QVector<int> TorrentInfo::fileIndicesForPiece(const int pieceIndex) const
{
if (!isValid() || (pieceIndex < 0) || (pieceIndex >= piecesCount()))
return QVector<int>();
return {};
const std::vector<libt::file_slice> files(
nativeInfo()->map_block(pieceIndex, 0, nativeInfo()->piece_size(pieceIndex)));

View File

@@ -59,12 +59,12 @@ TrackerEntry::Status TrackerEntry::status() const
// true when the tracker hasn't been tried yet.
if (m_nativeEntry.verified && m_nativeEntry.is_working())
return Working;
else if ((m_nativeEntry.fails == 0) && m_nativeEntry.updating)
if ((m_nativeEntry.fails == 0) && m_nativeEntry.updating)
return Updating;
else if (m_nativeEntry.fails == 0)
if (m_nativeEntry.fails == 0)
return NotContacted;
else
return NotWorking;
return NotWorking;
}
void TrackerEntry::setTier(const int value)

View File

@@ -74,7 +74,7 @@ Server::Server(IRequestHandler *requestHandler, QObject *parent)
setProxy(QNetworkProxy::NoProxy);
QSslSocket::setDefaultCiphers(safeCipherList());
QTimer *dropConnectionTimer = new QTimer(this);
auto *dropConnectionTimer = new QTimer(this);
connect(dropConnectionTimer, &QTimer::timeout, this, &Server::dropTimedOutConnection);
dropConnectionTimer->start(CONNECTIONS_SCAN_INTERVAL * 1000);
}
@@ -102,7 +102,7 @@ void Server::incomingConnection(qintptr socketDescriptor)
static_cast<QSslSocket *>(serverSocket)->startServerEncryption();
}
Connection *c = new Connection(serverSocket, m_requestHandler, this);
auto *c = new Connection(serverSocket, m_requestHandler, this);
m_connections.append(c);
}

View File

@@ -98,7 +98,7 @@ QVector<Log::Msg> Logger::getMessages(int lastKnownId) const
return m_messages;
if (diff <= 0)
return QVector<Log::Msg>();
return {};
return m_messages.mid(size - diff);
}
@@ -114,7 +114,7 @@ QVector<Log::Peer> Logger::getPeers(int lastKnownId) const
return m_peers;
if (diff <= 0)
return QVector<Log::Peer>();
return {};
return m_peers.mid(size - diff);
}

View File

@@ -288,11 +288,11 @@ QUrl DNSUpdater::getRegistrationUrl(int service)
{
switch (service) {
case DNS::DYNDNS:
return QUrl("https://www.dyndns.com/account/services/hosts/add.html");
return {"https://www.dyndns.com/account/services/hosts/add.html"};
case DNS::NOIP:
return QUrl("https://www.noip.com/remote-access");
return {"https://www.noip.com/remote-access"};
default:
Q_ASSERT(0);
}
return QUrl();
return {};
}

View File

@@ -129,7 +129,7 @@ QString GeoIPManager::lookup(const QHostAddress &hostAddr) const
if (m_enabled && m_geoIPDatabase)
return m_geoIPDatabase->lookup(hostAddr);
return QString();
return {};
}
QString GeoIPManager::CountryName(const QString &countryISOCode)

View File

@@ -171,14 +171,14 @@ QString GeoIPDatabase::lookup(const QHostAddress &hostAddr) const
ptr += m_recordBytes;
quint32 id = 0;
uchar *idPtr = reinterpret_cast<uchar *>(&id);
auto *idPtr = reinterpret_cast<uchar *>(&id);
memcpy(&idPtr[4 - m_recordBytes], ptr, m_recordBytes);
fromBigEndian(idPtr, 4);
if (id == m_nodeCount) {
return QString();
return {};
}
else if (id > m_nodeCount) {
if (id > m_nodeCount) {
QString country = m_countries.value(id);
if (country.isEmpty()) {
const quint32 offset = id - m_nodeCount - sizeof(DATA_SECTION_SEPARATOR);
@@ -191,13 +191,12 @@ QString GeoIPDatabase::lookup(const QHostAddress &hostAddr) const
}
return country;
}
else {
ptr = m_data + (id * m_nodeSize);
}
ptr = m_data + (id * m_nodeSize);
}
}
return QString();
return {};
}
#define CHECK_METADATA_REQ(key, type) \
@@ -205,7 +204,7 @@ if (!metadata.contains(#key)) { \
error = errMsgNotFound.arg(#key); \
return false; \
} \
else if (metadata.value(#key).userType() != QMetaType::type) { \
if (metadata.value(#key).userType() != QMetaType::type) { \
error = errMsgInvalid.arg(#key); \
return false; \
}
@@ -299,20 +298,20 @@ QVariantHash GeoIPDatabase::readMetadata() const
if (index >= 0) {
if (m_size > MAX_METADATA_SIZE)
index += (m_size - MAX_METADATA_SIZE); // from begin of all data
quint32 offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
auto offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
QVariant metadata = readDataField(offset);
if (metadata.userType() == QMetaType::QVariantHash)
return metadata.toHash();
}
return QVariantHash();
return {};
}
QVariant GeoIPDatabase::readDataField(quint32 &offset) const
{
DataFieldDescriptor descr;
if (!readDataFieldDescriptor(offset, descr))
return QVariant();
return {};
quint32 locOffset = offset;
bool usePointer = false;
@@ -321,7 +320,7 @@ QVariant GeoIPDatabase::readDataField(quint32 &offset) const
// convert offset from data section to global
locOffset = descr.offset + (m_nodeCount * m_recordSize / 4) + sizeof(DATA_SECTION_SEPARATOR);
if (!readDataFieldDescriptor(locOffset, descr))
return QVariant();
return {};
}
QVariant fieldValue;
@@ -460,12 +459,12 @@ QVariant GeoIPDatabase::readMapValue(quint32 &offset, quint32 count) const
for (quint32 i = 0; i < count; ++i) {
QVariant field = readDataField(offset);
if (field.userType() != QMetaType::QString)
return QVariant();
return {};
QString key = field.toString();
field = readDataField(offset);
if (field.userType() == QVariant::Invalid)
return QVariant();
return {};
map[key] = field;
}
@@ -480,7 +479,7 @@ QVariant GeoIPDatabase::readArrayValue(quint32 &offset, quint32 count) const
for (quint32 i = 0; i < count; ++i) {
QVariant field = readDataField(offset);
if (field.userType() == QVariant::Invalid)
return QVariant();
return {};
array.append(field);
}

View File

@@ -464,7 +464,7 @@ namespace
offset = parts[2].toInt(&ok[0]) * 3600;
int offsetMin = parts[3].toInt(&ok[1]);
if (!ok[0] || !ok[1] || offsetMin > 59)
return QDateTime();
return {};
offset += offsetMin * 60;
negOffset = (parts[1] == QLatin1String("-"));
if (negOffset)
@@ -494,7 +494,7 @@ namespace
for (int i = 0, end = zone.size(); (i < end) && !nonalpha; ++i)
nonalpha = !isalpha(zone[i]);
if (nonalpha)
return QDateTime();
return {};
// TODO: Attempt to recognize the time zone abbreviation?
negOffset = true; // unknown time zone: RFC 2822 treats as '-0000'
}
@@ -556,22 +556,20 @@ void Parser::parse_impl(const QByteArray &feedData)
foundChannel = true;
break;
}
else {
qDebug() << "Skip rss item: " << xml.name();
xml.skipCurrentElement();
}
qDebug() << "Skip rss item: " << xml.name();
xml.skipCurrentElement();
}
break;
}
else if (xml.name() == "feed") { // Atom feed
if (xml.name() == "feed") { // Atom feed
parseAtomChannel(xml);
foundChannel = true;
break;
}
else {
qDebug() << "Skip root item: " << xml.name();
xml.skipCurrentElement();
}
qDebug() << "Skip root item: " << xml.name();
xml.skipCurrentElement();
}
if (!foundChannel) {

View File

@@ -68,7 +68,7 @@ namespace
switch (static_cast<int>(triStateBool)) {
case 0: return false;
case 1: return true;
default: return QJsonValue();
default: return {};
}
}
@@ -159,7 +159,7 @@ QString computeEpisodeName(const QString &article)
// See if we can extract an season/episode number or date from the title
if (!match.hasMatch())
return QString();
return {};
QStringList ret;
for (int i = 1; i <= match.lastCapturedIndex(); ++i) {

View File

@@ -81,8 +81,8 @@ QString Item::joinPath(const QString &path1, const QString &path2)
{
if (path1.isEmpty())
return path2;
else
return path1 + Item::PathSeparator + path2;
return (path1 + Item::PathSeparator + path2);
}
QStringList Item::expandPath(const QString &path)

View File

@@ -107,7 +107,7 @@ int ScanFoldersModel::columnCount(const QModelIndex &parent) const
QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || (index.row() >= rowCount()))
return QVariant();
return {};
const PathData *pathData = m_pathList.at(index.row());
QVariant value;
@@ -141,7 +141,7 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
QVariant ScanFoldersModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if ((orientation != Qt::Horizontal) || (role != Qt::DisplayRole) || (section < 0) || (section >= columnCount()))
return QVariant();
return {};
QVariant title;
@@ -183,7 +183,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
return false;
if (role == Qt::UserRole) {
PathType type = static_cast<PathType>(value.toInt());
auto type = static_cast<PathType>(value.toInt());
if (type == CUSTOM_LOCATION)
return false;
@@ -311,7 +311,7 @@ QString ScanFoldersModel::downloadPathTorrentFolder(const QString &filePath) con
if (data->downloadType == CUSTOM_LOCATION)
return data->downloadPath;
return QString();
return {};
}
int ScanFoldersModel::findPathData(const QString &path) const
@@ -399,5 +399,5 @@ QString ScanFoldersModel::pathTypeDisplayName(const PathType type)
default:
qDebug("Invalid PathType: %d", type);
};
return QString();
return {};
}

View File

@@ -282,7 +282,7 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da
SettingsPtr settings = Profile::instance().applicationSettings(name);
if (settings->allKeys().isEmpty())
return QString();
return {};
// Copy everything into memory. This means even keys inserted in the file manually
// or that we don't touch directly in this code (eg disabled by ifdef). This ensures
@@ -314,5 +314,5 @@ QString TransactionalSettings::serialize(const QString &name, const QVariantHash
Logger::instance()->addMessage(QObject::tr("An unknown error occurred while trying to write the configuration file."), Log::CRITICAL);
break;
}
return QString();
return {};
}

View File

@@ -86,4 +86,3 @@ CachedSettingValue<TorrentFileGuard::AutoDeleteMode> &TorrentFileGuard::autoDele
static CachedSettingValue<AutoDeleteMode> setting("Core/AutoDeleteAddedTorrentFile", AutoDeleteMode::Never);
return setting;
}

View File

@@ -26,8 +26,7 @@
* exception statement from your version.
*/
#ifndef TOFFENTFILEGURAD_H
#define TOFFENTFILEGURAD_H
#pragma once
#include <QObject>
#include <QString>
@@ -82,5 +81,3 @@ private:
AutoDeleteMode m_mode;
bool m_wasAdded;
};
#endif // TOFFENTFILEGURAD_H

View File

@@ -44,7 +44,6 @@ const TorrentFilter TorrentFilter::InactiveTorrent(TorrentFilter::Inactive);
const TorrentFilter TorrentFilter::ErroredTorrent(TorrentFilter::Errored);
using BitTorrent::TorrentHandle;
using BitTorrent::TorrentState;
TorrentFilter::TorrentFilter()
: m_type(All)
@@ -174,19 +173,22 @@ bool TorrentFilter::matchState(const BitTorrent::TorrentHandle *const torrent) c
bool TorrentFilter::matchHash(const BitTorrent::TorrentHandle *const torrent) const
{
if (m_hashSet == AnyHash) return true;
else return m_hashSet.contains(torrent->hash());
return m_hashSet.contains(torrent->hash());
}
bool TorrentFilter::matchCategory(const BitTorrent::TorrentHandle *const torrent) const
{
if (m_category.isNull()) return true;
else return (torrent->belongsToCategory(m_category));
return (torrent->belongsToCategory(m_category));
}
bool TorrentFilter::matchTag(const BitTorrent::TorrentHandle *const torrent) const
{
// Empty tag is a special value to indicate we're filtering for untagged torrents.
if (m_tag.isNull()) return true;
else if (m_tag.isEmpty()) return torrent->tags().isEmpty();
else return (torrent->hasTag(m_tag));
if (m_tag.isEmpty()) return torrent->tags().isEmpty();
return (torrent->hasTag(m_tag));
}

View File

@@ -227,7 +227,7 @@ namespace
return path;
}
return QString();
return {};
}
#endif // Q_OS_WIN
}

View File

@@ -97,7 +97,7 @@ namespace
if (sizeInBytes < 0) return false;
int i = 0;
qreal rawVal = static_cast<qreal>(sizeInBytes);
auto rawVal = static_cast<qreal>(sizeInBytes);
while ((rawVal >= 1024.) && (i <= static_cast<int>(Utils::Misc::SizeUnit::ExbiByte))) {
rawVal /= 1024.;
@@ -256,7 +256,7 @@ QPoint Utils::Misc::screenCenter(const QWidget *w)
QDesktopWidget *desktop = QApplication::desktop();
int scrn = desktop->screenNumber(parent); // fallback to `primaryScreen` when parent is invalid
QRect r = desktop->availableGeometry(scrn);
return QPoint(r.x() + (r.width() - w->frameSize().width()) / 2, r.y() + (r.height() - w->frameSize().height()) / 2);
return {r.x() + (r.width() - w->frameSize().width()) / 2, r.y() + (r.height() - w->frameSize().height()) / 2};
}
#endif
@@ -285,8 +285,8 @@ int Utils::Misc::friendlyUnitPrecision(SizeUnit unit)
// friendlyUnit's number of digits after the decimal point
if (unit == SizeUnit::Byte) return 0;
if (unit <= SizeUnit::MebiByte) return 1;
else if (unit == SizeUnit::GibiByte) return 2;
else return 3;
if (unit == SizeUnit::GibiByte) return 2;
return 3;
}
qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit)

View File

@@ -110,7 +110,7 @@ namespace Utils
QSslKey key {data, QSsl::Rsa};
if (!key.isNull())
return key;
return QSslKey(data, QSsl::Ec);
return {data, QSsl::Ec};
}
bool isSSLKeyValid(const QByteArray &data)