Skip to content

Commit

Permalink
Merge bitcoin#15114: Qt: Replace remaining 0 with nullptr
Browse files Browse the repository at this point in the history
3a0e76f Replace remaining 0 with nullptr in Qt code (Ben Woosley)
9096276 Don't use zero as null pointer constant (-Wzero-as-null-pointer-constant) (practicalswift)

Pull request description:

  This corrects all violations of `-Wzero-as-null-pointer-constant` identified in the Qt codebase.

  These changes are extracted from bitcoin#15112 as suggested by @MarcoFalke to ease review. This is in service of enabling `-Wzero-as-null-pointer-constant`, which should eliminate this as a concern going forward.

  Note there are 2 non-Qt changes: `src/test/allocator_tests.cpp` and `src/wallet/db.cpp`.

Tree-SHA512: 206bd668802147ba42bc413c2d7d259cb59aca9ec1da74a6bf2ca3932e60ae492faacbc61bcee0fd6b4b49a4d59d075b7e5404f0526b36c47718f9b0587e7768
  • Loading branch information
laanwj authored and Munkybooty committed Aug 24, 2021
1 parent 583c2ee commit f239861
Show file tree
Hide file tree
Showing 56 changed files with 111 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel
AddressBookPage::AddressBookPage(Mode _mode, Tabs _tab, QWidget* parent) :
QDialog(parent),
ui(new Ui::AddressBookPage),
model(0),
model(nullptr),
mode(_mode),
tab(_tab)
{
Expand Down
2 changes: 1 addition & 1 deletion src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AddressBookPage : public QDialog
ForEditing /**< Open address book for editing */
};

explicit AddressBookPage(Mode mode, Tabs tab, QWidget* parent = 0);
explicit AddressBookPage(Mode mode, Tabs tab, QWidget* parent = nullptr);
~AddressBookPage();

void setModel(AddressTableModel *model);
Expand Down
6 changes: 3 additions & 3 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class AddressTablePriv
}
else
{
return 0;
return nullptr;
}
}
};
Expand Down Expand Up @@ -306,8 +306,8 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,

Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
if (!index.isValid()) return Qt::NoItemFlags;

AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/addresstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AddressTableModel : public QAbstractTableModel
Q_OBJECT

public:
explicit AddressTableModel(WalletModel *parent = 0);
explicit AddressTableModel(WalletModel *parent = nullptr);
~AddressTableModel();

enum ColumnIndex {
Expand Down
2 changes: 1 addition & 1 deletion src/qt/askpassphrasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::AskPassphraseDialog),
mode(_mode),
model(0),
model(nullptr),
fCapsLock(false)
{
ui->setupUi(this);
Expand Down
5 changes: 2 additions & 3 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BanTablePriv
if (idx >= 0 && idx < cachedBanlist.size())
return &cachedBanlist[idx];

return 0;
return nullptr;
}
};

Expand Down Expand Up @@ -151,8 +151,7 @@ QVariant BanTableModel::headerData(int section, Qt::Orientation orientation, int

Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
if (!index.isValid()) return Qt::NoItemFlags;

Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
return retval;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bantablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BanTableModel : public QAbstractTableModel
Q_OBJECT

public:
explicit BanTableModel(interfaces::Node& node, ClientModel *parent = 0);
explicit BanTableModel(interfaces::Node& node, ClientModel *parent = nullptr);
~BanTableModel();
void startAutoRefresh();
void stopAutoRefresh();
Expand Down
6 changes: 3 additions & 3 deletions src/qt/bitcoinamountfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* return validity.
* @note Must return 0 if !valid.
*/
static CAmount parse(const QString &text, int nUnit, bool *valid_out=0)
static CAmount parse(const QString &text, int nUnit, bool *valid_out= nullptr)
{
CAmount val = 0;
bool valid = BitcoinUnits::parse(nUnit, text, &val);
Expand Down Expand Up @@ -87,7 +87,7 @@ class AmountLineEdit: public QLineEdit
}
}

CAmount value(bool *valid_out=0) const
CAmount value(bool *valid_out=nullptr) const
{
return parse(text(), currentUnit, valid_out);
}
Expand Down Expand Up @@ -158,7 +158,7 @@ class AmountLineEdit: public QLineEdit

BitcoinAmountField::BitcoinAmountField(QWidget *parent) :
QWidget(parent),
amount(0)
amount(nullptr)
{
amount = new AmountLineEdit(this);
amount->setLocale(QLocale::c());
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoinamountfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class BitcoinAmountField: public QWidget
Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY valueChanged USER true)

public:
explicit BitcoinAmountField(QWidget *parent = 0);
explicit BitcoinAmountField(QWidget *parent = nullptr);

CAmount value(bool *value=0) const;
CAmount value(bool *value=nullptr) const;
void setValue(const CAmount& value);

/** Make read-only **/
Expand Down
8 changes: 4 additions & 4 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ void BitcoinGUI::updateProxyIcon()
bool proxy_enabled = clientModel->getProxyInfo(ip_port);

if (proxy_enabled) {
if (labelProxyIcon->pixmap() == 0) {
if (labelProxyIcon->pixmap() == nullptr) {
QString ip_port_q = QString::fromStdString(ip_port);
labelProxyIcon->setPixmap(GUIUtil::getIcon("proxy", GUIUtil::ThemedColor::GREEN).pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));
Expand Down Expand Up @@ -1743,7 +1743,7 @@ void BitcoinGUI::showProgress(const QString &title, int nProgress)
progressDialog = new QProgressDialog(title, "", 0, 100, this);
progressDialog->setWindowModality(Qt::ApplicationModal);
progressDialog->setMinimumDuration(0);
progressDialog->setCancelButton(0);
progressDialog->setCancelButton(nullptr);
progressDialog->setAutoClose(false);
progressDialog->setValue(0);
}
Expand Down Expand Up @@ -1818,8 +1818,8 @@ void BitcoinGUI::handleRestart(QStringList args)
}

UnitDisplayStatusBarControl::UnitDisplayStatusBarControl() :
optionsModel(0),
menu(0)
optionsModel(nullptr),
menu(nullptr)
{
createContextMenu();
setToolTip(tr("Unit to show amounts in. Click to select another unit."));
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BitcoinGUI : public QMainWindow
public:
static const std::string DEFAULT_UIPLATFORM;

explicit BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent = 0);
explicit BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent = nullptr);
~BitcoinGUI();

/** Set the client model.
Expand Down
6 changes: 3 additions & 3 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ ClientModel::ClientModel(interfaces::Node& node, OptionsModel *_optionsModel, QO
QObject(parent),
m_node(node),
optionsModel(_optionsModel),
peerTableModel(0),
banTableModel(0),
pollTimer(0)
peerTableModel(nullptr),
banTableModel(nullptr),
pollTimer(nullptr)
{
cachedBestHeaderHeight = -1;
cachedBestHeaderTime = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ClientModel : public QObject
Q_OBJECT

public:
explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = 0);
explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
~ClientModel();

interfaces::Node& node() const { return m_node; }
Expand Down
2 changes: 1 addition & 1 deletion src/qt/coincontroltreewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CoinControlTreeWidget : public QTreeWidget
Q_OBJECT

public:
explicit CoinControlTreeWidget(QWidget *parent = 0);
explicit CoinControlTreeWidget(QWidget *parent = nullptr);

protected:
virtual void keyPressEvent(QKeyEvent *event) override;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/csvmodelwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

CSVModelWriter::CSVModelWriter(const QString &_filename, QObject *parent) :
QObject(parent),
filename(_filename), model(0)
filename(_filename), model(nullptr)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/csvmodelwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CSVModelWriter : public QObject
Q_OBJECT

public:
explicit CSVModelWriter(const QString &filename, QObject *parent = 0);
explicit CSVModelWriter(const QString &filename, QObject *parent = nullptr);

void setModel(const QAbstractItemModel *model);
void addColumn(const QString &title, int column, int role=Qt::EditRole);
Expand Down
38 changes: 19 additions & 19 deletions src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ void BitcoinCore::shutdown()

BitcoinApplication::BitcoinApplication(interfaces::Node& node, int &argc, char **argv):
QApplication(argc, argv),
coreThread(0),
coreThread(nullptr),
m_node(node),
optionsModel(0),
clientModel(0),
window(0),
pollShutdownTimer(0),
optionsModel(nullptr),
clientModel(nullptr),
window(nullptr),
pollShutdownTimer(nullptr),
#ifdef ENABLE_WALLET
paymentServer(0),
paymentServer(nullptr),
m_wallet_models(),
#endif
returnValue(0)
Expand All @@ -320,10 +320,10 @@ BitcoinApplication::~BitcoinApplication()
}

delete window;
window = 0;
window = nullptr;
#ifdef ENABLE_WALLET
delete paymentServer;
paymentServer = 0;
paymentServer = nullptr;
#endif
// Delete Qt-settings if user clicked on "Reset Options"
QSettings settings;
Expand All @@ -332,7 +332,7 @@ BitcoinApplication::~BitcoinApplication()
settings.sync();
}
delete optionsModel;
optionsModel = 0;
optionsModel = nullptr;
}

#ifdef ENABLE_WALLET
Expand All @@ -349,14 +349,14 @@ void BitcoinApplication::createOptionsModel(bool resetSettings)

void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
{
window = new BitcoinGUI(m_node, networkStyle, 0);
window = new BitcoinGUI(m_node, networkStyle, nullptr);
pollShutdownTimer = new QTimer(window);
connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
}

void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
SplashScreen *splash = new SplashScreen(m_node, 0, networkStyle);
SplashScreen *splash = new SplashScreen(m_node, nullptr, networkStyle);
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when slotFinish happens.
splash->show();
Expand Down Expand Up @@ -413,7 +413,7 @@ void BitcoinApplication::requestShutdown()
qDebug() << __func__ << ": Requesting shutdown";
startThread();
window->hide();
window->setClientModel(0);
window->setClientModel(nullptr);
pollShutdownTimer->stop();

#ifdef ENABLE_WALLET
Expand All @@ -424,7 +424,7 @@ void BitcoinApplication::requestShutdown()
m_wallet_models.clear();
#endif
delete clientModel;
clientModel = 0;
clientModel = nullptr;

m_node.startShutdown();

Expand Down Expand Up @@ -526,7 +526,7 @@ void BitcoinApplication::shutdownResult()

void BitcoinApplication::handleRunawayException(const QString &message)
{
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. Dash Core can no longer continue safely and will quit.") + QString("\n\n") + message);
QMessageBox::critical(nullptr, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. Dash Core can no longer continue safely and will quit.") + QString("\n\n") + message);
::exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -608,7 +608,7 @@ int main(int argc, char *argv[])
SetupUIArgs();
std::string error;
if (!node->parseParameters(argc, argv, error)) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME),
QObject::tr("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -649,12 +649,12 @@ int main(int argc, char *argv[])
/// - Do not call GetDataDir(true) before this step finishes
if (!fs::is_directory(GetDataDir(false)))
{
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME),
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
return EXIT_FAILURE;
}
if (!node->readConfigFiles(error)) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME),
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
return EXIT_FAILURE;
}
Expand All @@ -669,7 +669,7 @@ int main(int argc, char *argv[])
try {
node->selectParams(gArgs.GetChainName());
} catch(std::exception &e) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
return EXIT_FAILURE;
}
#ifdef ENABLE_WALLET
Expand Down
4 changes: 2 additions & 2 deletions src/qt/editaddressdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::EditAddressDialog),
mapper(0),
mapper(nullptr),
mode(_mode),
model(0)
model(nullptr)
{
ui->setupUi(this);

Expand Down
2 changes: 1 addition & 1 deletion src/qt/editaddressdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EditAddressDialog : public QDialog
EditSendingAddress
};

explicit EditAddressDialog(Mode mode, QWidget *parent = 0);
explicit EditAddressDialog(Mode mode, QWidget *parent = nullptr);
~EditAddressDialog();

void setModel(AddressTableModel *model);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace GUIUtil
Q_OBJECT

public:
explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = nullptr);

protected:
bool eventFilter(QObject *obj, QEvent *evt) override;
Expand Down
6 changes: 3 additions & 3 deletions src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void FreespaceChecker::check()
Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_size) :
QDialog(parent),
ui(new Ui::Intro),
thread(0),
thread(nullptr),
signalled(false),
m_blockchain_size(blockchain_size),
m_chain_state_size(chain_state_size)
Expand Down Expand Up @@ -232,7 +232,7 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
}
break;
} catch (const fs::filesystem_error&) {
QMessageBox::critical(0, tr(PACKAGE_NAME),
QMessageBox::critical(nullptr, tr(PACKAGE_NAME),
tr("Error: Specified data directory \"%1\" cannot be created.").arg(dataDir));
/* fall through, back to choosing screen */
}
Expand Down Expand Up @@ -292,7 +292,7 @@ void Intro::on_dataDirectory_textChanged(const QString &dataDirStr)

void Intro::on_ellipsisButton_clicked()
{
QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(0, "Choose data directory", ui->dataDirectory->text()));
QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(nullptr, "Choose data directory", ui->dataDirectory->text()));
if(!dir.isEmpty())
ui->dataDirectory->setText(dir);
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/intro.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Intro : public QDialog
Q_OBJECT

public:
explicit Intro(QWidget *parent = 0,
explicit Intro(QWidget *parent = nullptr,
uint64_t blockchain_size = 0, uint64_t chain_state_size = 0);
~Intro();

Expand Down
Loading

0 comments on commit f239861

Please sign in to comment.