UI: Don't explicitly compare pointers to nullptr in C++.

This commit is contained in:
Nodir Temirkhodjaev 2021-04-07 11:41:35 +03:00
parent b10340c394
commit 2679c82275
13 changed files with 36 additions and 36 deletions

View File

@ -67,7 +67,7 @@ bool SqliteDb::open()
void SqliteDb::close()
{
if (m_db != nullptr) {
if (m_db) {
sqlite3_close(m_db);
m_db = nullptr;
}
@ -119,7 +119,7 @@ QVariant SqliteDb::executeEx(const char *sql, const QVariantList &vars, int resu
}
}
if (ok != nullptr) {
if (ok) {
*ok = success;
}
@ -178,19 +178,19 @@ bool SqliteDb::rollbackTransaction()
bool SqliteDb::beginSavepoint(const char *name)
{
return (name == nullptr) ? execute("SAVEPOINT _;")
: executeStr(QString("SAVEPOINT %1;").arg(name));
return !name ? execute("SAVEPOINT _;")
: executeStr(QString("SAVEPOINT %1;").arg(name));
}
bool SqliteDb::releaseSavepoint(const char *name)
{
return (name == nullptr) ? execute("RELEASE _;") : executeStr(QString("RELEASE %1;").arg(name));
return !name ? execute("RELEASE _;") : executeStr(QString("RELEASE %1;").arg(name));
}
bool SqliteDb::rollbackSavepoint(const char *name)
{
return (name == nullptr) ? execute("ROLLBACK TO _;")
: executeStr(QString("ROLLBACK TO %1;").arg(name));
return !name ? execute("ROLLBACK TO _;")
: executeStr(QString("ROLLBACK TO %1;").arg(name));
}
int SqliteDb::errorCode() const
@ -351,7 +351,7 @@ bool SqliteDb::migrate(const QString &sqlDir, const char *sqlPragmas, int versio
success = execute(data.constData());
}
if (success && migrateFunc != nullptr) {
if (success && migrateFunc) {
success = migrateFunc(this, userVersion, isNewDb, migrateContext);
}
@ -441,7 +441,7 @@ bool SqliteDb::importDb(
}
}
if (success && migrateFunc != nullptr) {
if (success && migrateFunc) {
success = migrateFunc(this, userVersion(), false, migrateContext);
}

View File

@ -20,7 +20,7 @@ bool SqliteStmt::prepare(sqlite3 *db, const char *sql, SqliteStmt::PrepareFlags
void SqliteStmt::finalize()
{
if (m_stmt != nullptr) {
if (m_stmt) {
sqlite3_finalize(m_stmt);
m_stmt = nullptr;
}
@ -220,7 +220,7 @@ bool SqliteStmt::columnBool(int column)
QString SqliteStmt::columnText(int column)
{
const char *p = reinterpret_cast<const char *>(sqlite3_column_text(m_stmt, column));
if (p == nullptr || *p == '\0')
if (!p || *p == '\0')
return QString();
const int bytesCount = sqlite3_column_bytes(m_stmt, column);
@ -245,7 +245,7 @@ QDateTime SqliteStmt::columnUnixTime(int column)
QByteArray SqliteStmt::columnBlob(int column)
{
const char *p = static_cast<const char *>(sqlite3_column_blob(m_stmt, column));
if (p == nullptr)
if (!p)
return QByteArray();
const int bytesCount = sqlite3_column_bytes(m_stmt, column);

View File

@ -196,7 +196,7 @@ bool loadAddressGroups(SqliteDb *db, const QList<AddressGroup *> &addressGroups,
index = 0;
while (stmt.step() == SqliteStmt::StepRow) {
auto addrGroup = addressGroups.at(index);
Q_ASSERT(addrGroup != nullptr);
Q_ASSERT(addrGroup);
addrGroup->setId(stmt.columnInt64(0));
addrGroup->setIncludeAll(stmt.columnBool(1));
@ -383,7 +383,7 @@ void ConfManager::setConfToEdit(FirewallConf *conf)
if (m_confToEdit == conf)
return;
if (m_confToEdit != nullptr && m_confToEdit != m_conf) {
if (m_confToEdit && m_confToEdit != m_conf) {
m_confToEdit->deleteLater();
}

View File

@ -80,7 +80,7 @@ void TableView::currentChanged(const QModelIndex &current, const QModelIndex &pr
void TableView::contextMenuEvent(QContextMenuEvent *event)
{
if (m_menu != nullptr) {
if (m_menu) {
m_menu->popup(event->globalPos());
}
}

View File

@ -594,7 +594,7 @@ bool FortManager::checkPassword()
if (g_passwordDialogOpened) {
auto dialog = qApp->activeModalWidget();
if (dialog != nullptr) {
if (dialog) {
dialog->activateWindow();
}
return false;
@ -653,7 +653,7 @@ bool FortManager::saveOriginConf(const QString &message, bool onlyFlags)
bool FortManager::saveConf(bool onlyFlags)
{
Q_ASSERT(confToEdit() != nullptr);
Q_ASSERT(confToEdit());
return saveConf(confToEdit(), onlyFlags);
}
@ -663,7 +663,7 @@ bool FortManager::applyConf(bool onlyFlags)
if (!saveConf(onlyFlags))
return false;
Q_ASSERT(confToEdit() == nullptr);
Q_ASSERT(!confToEdit());
confManager()->initConfToEdit();
@ -672,7 +672,7 @@ bool FortManager::applyConf(bool onlyFlags)
bool FortManager::applyConfImmediateFlags()
{
if (confToEdit() != nullptr) {
if (confToEdit()) {
conf()->copyImmediateFlags(*confToEdit());
}
@ -842,14 +842,14 @@ void FortManager::updateTrayIcon(bool alerted)
void FortManager::updateTrayMenu(bool onlyFlags)
{
QMenu *oldMenu = m_trayIcon->contextMenu();
if (oldMenu != nullptr && !onlyFlags) {
if (oldMenu && !onlyFlags) {
oldMenu->deleteLater();
oldMenu = nullptr;
removeHotKeys();
}
if (oldMenu == nullptr) {
if (!oldMenu) {
createTrayMenu();
retranslateTrayMenu();
}
@ -923,7 +923,7 @@ void FortManager::createTrayMenu()
void FortManager::updateTrayMenuFlags()
{
const bool editEnabled = (!isPasswordRequired() && m_optWindow == nullptr);
const bool editEnabled = (!isPasswordRequired() && !m_optWindow);
m_filterEnabledAction->setEnabled(editEnabled);
m_stopTrafficAction->setEnabled(editEnabled);

View File

@ -705,7 +705,7 @@ SqliteStmt *StatManager::getSqliteStmt(const char *sql)
{
SqliteStmt *stmt = m_sqliteStmts.value(sql);
if (stmt == nullptr) {
if (!stmt) {
stmt = new SqliteStmt();
stmt->prepare(m_sqliteDb->db(), sql, SqliteStmt::PreparePersistent);

View File

@ -12,14 +12,14 @@ void TaskDownloader::run()
setupDownloader();
if (m_downloader != nullptr) {
if (m_downloader) {
m_downloader->start();
}
}
void TaskDownloader::abort(bool success)
{
if (m_downloader == nullptr)
if (!m_downloader)
return;
m_downloader->disconnect(this); // to avoid recursive call on abort()

View File

@ -180,7 +180,7 @@ void TaskInfo::setupTaskWorker()
void TaskInfo::runTaskWorker()
{
if (aborted() || taskWorker() == nullptr)
if (aborted() || !taskWorker())
return;
taskWorker()->run();
@ -194,7 +194,7 @@ void TaskInfo::abort()
// to avoid recursive call on worker.abort() -> handleFinished(false) -> abort()
m_aborted = true;
if (taskWorker() != nullptr) {
if (taskWorker()) {
taskWorker()->abort();
taskWorker()->deleteLater();

View File

@ -13,7 +13,7 @@ AppInfoCache::AppInfoCache(QObject *parent) : QObject(parent), m_cache(1000)
void AppInfoCache::setManager(AppInfoManager *manager)
{
Q_ASSERT(manager != nullptr);
Q_ASSERT(manager);
m_manager = manager;
@ -53,7 +53,7 @@ AppInfo AppInfoCache::appInfo(const QString &appPath)
AppInfo *appInfo = m_cache.object(appPath);
bool lookupRequired = false;
if (appInfo == nullptr) {
if (!appInfo) {
appInfo = new AppInfo();
m_cache.insert(appPath, appInfo, 1);
@ -62,7 +62,7 @@ AppInfo AppInfoCache::appInfo(const QString &appPath)
lookupRequired = appInfo->isFileModified(appPath);
}
if (lookupRequired && m_manager != nullptr) {
if (lookupRequired && m_manager) {
m_manager->lookupAppInfo(appPath);
}
@ -72,7 +72,7 @@ AppInfo AppInfoCache::appInfo(const QString &appPath)
void AppInfoCache::handleFinishedLookup(const QString &appPath, const AppInfo info)
{
AppInfo *appInfo = m_cache.object(appPath);
if (appInfo == nullptr)
if (!appInfo)
return;
*appInfo = info;

View File

@ -352,7 +352,7 @@ bool ConfUtil::parseAppGroups(EnvManager &envManager, const QList<AppGroup *> &a
bool ConfUtil::parseExeApps(
ConfAppsWalker *confAppsWalker, appentry_map_t &exeAppsMap, quint32 &exeAppsSize)
{
if (Q_UNLIKELY(confAppsWalker == nullptr))
if (Q_UNLIKELY(!confAppsWalker))
return true;
return confAppsWalker->walkApps([&](int groupIndex, bool useGroupPerm, bool blocked,

View File

@ -97,7 +97,7 @@ bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *mes
}
case WM_SETTINGCHANGE: {
const auto src = reinterpret_cast<const wchar_t *>(msg->lParam);
if (src != nullptr && wcscmp(src, L"Environment") == 0) {
if (src && wcscmp(src, L"Environment") == 0) {
emit environmentChanged();
}
break;

View File

@ -15,7 +15,7 @@ QString HostInfoCache::hostName(const QString &address)
{
HostInfo *hostInfo = m_cache.object(address);
if (hostInfo == nullptr) {
if (!hostInfo) {
hostInfo = new HostInfo();
m_cache.insert(address, hostInfo, 1);
@ -36,7 +36,7 @@ void HostInfoCache::clear()
void HostInfoCache::handleFinishedLookup(const QString &address, const QString &hostName)
{
HostInfo *hostInfo = m_cache.object(address);
if (hostInfo == nullptr)
if (!hostInfo)
return;
hostInfo->hostName = hostName;

View File

@ -9,7 +9,7 @@ void WorkerObject::run()
{
for (;;) {
WorkerJob *job = manager()->dequeueJob();
if (job == nullptr)
if (!job)
break;
doJob(job);