Skip to content

Commit 7633529

Browse files
committed
Merge #15114: Qt: Replace remaining 0 with nullptr
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 #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
2 parents 070eaf7 + 3a0e76f commit 7633529

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+123
-125
lines changed

src/qt/addressbookpage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel
5959
AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode, Tabs _tab, QWidget *parent) :
6060
QDialog(parent),
6161
ui(new Ui::AddressBookPage),
62-
model(0),
62+
model(nullptr),
6363
mode(_mode),
6464
tab(_tab)
6565
{

src/qt/addressbookpage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AddressBookPage : public QDialog
3838
ForEditing /**< Open address book for editing */
3939
};
4040

41-
explicit AddressBookPage(const PlatformStyle *platformStyle, Mode mode, Tabs tab, QWidget *parent = 0);
41+
explicit AddressBookPage(const PlatformStyle *platformStyle, Mode mode, Tabs tab, QWidget *parent = nullptr);
4242
~AddressBookPage();
4343

4444
void setModel(AddressTableModel *model);

src/qt/addresstablemodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class AddressTablePriv
153153
}
154154
else
155155
{
156-
return 0;
156+
return nullptr;
157157
}
158158
}
159159
};
@@ -300,8 +300,8 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,
300300

301301
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
302302
{
303-
if(!index.isValid())
304-
return 0;
303+
if (!index.isValid()) return Qt::NoItemFlags;
304+
305305
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
306306

307307
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;

src/qt/addresstablemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AddressTableModel : public QAbstractTableModel
2525
Q_OBJECT
2626

2727
public:
28-
explicit AddressTableModel(WalletModel *parent = 0);
28+
explicit AddressTableModel(WalletModel *parent = nullptr);
2929
~AddressTableModel();
3030

3131
enum ColumnIndex {

src/qt/askpassphrasedialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent) :
2222
QDialog(parent),
2323
ui(new Ui::AskPassphraseDialog),
2424
mode(_mode),
25-
model(0),
25+
model(nullptr),
2626
fCapsLock(false)
2727
{
2828
ui->setupUi(this);

src/qt/bantablemodel.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class BanTablePriv
7676
if (idx >= 0 && idx < cachedBanlist.size())
7777
return &cachedBanlist[idx];
7878

79-
return 0;
79+
return nullptr;
8080
}
8181
};
8282

@@ -145,8 +145,7 @@ QVariant BanTableModel::headerData(int section, Qt::Orientation orientation, int
145145

146146
Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
147147
{
148-
if(!index.isValid())
149-
return 0;
148+
if (!index.isValid()) return Qt::NoItemFlags;
150149

151150
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
152151
return retval;

src/qt/bantablemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BanTableModel : public QAbstractTableModel
4545
Q_OBJECT
4646

4747
public:
48-
explicit BanTableModel(interfaces::Node& node, ClientModel *parent = 0);
48+
explicit BanTableModel(interfaces::Node& node, ClientModel *parent = nullptr);
4949
~BanTableModel();
5050
void startAutoRefresh();
5151
void stopAutoRefresh();

src/qt/bitcoin.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,18 @@ void BitcoinCore::shutdown()
178178

179179
BitcoinApplication::BitcoinApplication(interfaces::Node& node, int &argc, char **argv):
180180
QApplication(argc, argv),
181-
coreThread(0),
181+
coreThread(nullptr),
182182
m_node(node),
183-
optionsModel(0),
184-
clientModel(0),
185-
window(0),
186-
pollShutdownTimer(0),
183+
optionsModel(nullptr),
184+
clientModel(nullptr),
185+
window(nullptr),
186+
pollShutdownTimer(nullptr),
187187
#ifdef ENABLE_WALLET
188-
paymentServer(0),
188+
paymentServer(nullptr),
189189
m_wallet_models(),
190190
#endif
191191
returnValue(0),
192-
platformStyle(0)
192+
platformStyle(nullptr)
193193
{
194194
setQuitOnLastWindowClosed(false);
195195
}
@@ -218,15 +218,15 @@ BitcoinApplication::~BitcoinApplication()
218218
}
219219

220220
delete window;
221-
window = 0;
221+
window = nullptr;
222222
#ifdef ENABLE_WALLET
223223
delete paymentServer;
224-
paymentServer = 0;
224+
paymentServer = nullptr;
225225
#endif
226226
delete optionsModel;
227-
optionsModel = 0;
227+
optionsModel = nullptr;
228228
delete platformStyle;
229-
platformStyle = 0;
229+
platformStyle = nullptr;
230230
}
231231

232232
#ifdef ENABLE_WALLET
@@ -243,15 +243,15 @@ void BitcoinApplication::createOptionsModel(bool resetSettings)
243243

244244
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
245245
{
246-
window = new BitcoinGUI(m_node, platformStyle, networkStyle, 0);
246+
window = new BitcoinGUI(m_node, platformStyle, networkStyle, nullptr);
247247

248248
pollShutdownTimer = new QTimer(window);
249249
connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
250250
}
251251

252252
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
253253
{
254-
SplashScreen *splash = new SplashScreen(m_node, 0, networkStyle);
254+
SplashScreen *splash = new SplashScreen(m_node, nullptr, networkStyle);
255255
// We don't hold a direct pointer to the splash screen after creation, but the splash
256256
// screen will take care of deleting itself when finish() happens.
257257
splash->show();
@@ -312,7 +312,7 @@ void BitcoinApplication::requestShutdown()
312312
qDebug() << __func__ << ": Requesting shutdown";
313313
startThread();
314314
window->hide();
315-
window->setClientModel(0);
315+
window->setClientModel(nullptr);
316316
pollShutdownTimer->stop();
317317

318318
#ifdef ENABLE_WALLET
@@ -323,7 +323,7 @@ void BitcoinApplication::requestShutdown()
323323
m_wallet_models.clear();
324324
#endif
325325
delete clientModel;
326-
clientModel = 0;
326+
clientModel = nullptr;
327327

328328
m_node.startShutdown();
329329

@@ -429,7 +429,7 @@ void BitcoinApplication::shutdownResult()
429429

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

@@ -503,7 +503,7 @@ int GuiMain(int argc, char* argv[])
503503
SetupUIArgs();
504504
std::string error;
505505
if (!node->parseParameters(argc, argv, error)) {
506-
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
506+
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME),
507507
QObject::tr("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
508508
return EXIT_FAILURE;
509509
}
@@ -540,12 +540,12 @@ int GuiMain(int argc, char* argv[])
540540
/// - Do not call GetDataDir(true) before this step finishes
541541
if (!fs::is_directory(GetDataDir(false)))
542542
{
543-
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
544-
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
543+
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME),
544+
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
545545
return EXIT_FAILURE;
546546
}
547547
if (!node->readConfigFiles(error)) {
548-
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
548+
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME),
549549
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
550550
return EXIT_FAILURE;
551551
}
@@ -560,7 +560,7 @@ int GuiMain(int argc, char* argv[])
560560
try {
561561
node->selectParams(gArgs.GetChainName());
562562
} catch(std::exception &e) {
563-
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
563+
QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
564564
return EXIT_FAILURE;
565565
}
566566
#ifdef ENABLE_WALLET

src/qt/bitcoinamountfield.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AmountSpinBox: public QAbstractSpinBox
6060
}
6161
}
6262

63-
CAmount value(bool *valid_out=0) const
63+
CAmount value(bool *valid_out=nullptr) const
6464
{
6565
return parse(text(), valid_out);
6666
}
@@ -159,7 +159,7 @@ class AmountSpinBox: public QAbstractSpinBox
159159
* return validity.
160160
* @note Must return 0 if !valid.
161161
*/
162-
CAmount parse(const QString &text, bool *valid_out=0) const
162+
CAmount parse(const QString &text, bool *valid_out=nullptr) const
163163
{
164164
CAmount val = 0;
165165
bool valid = BitcoinUnits::parse(currentUnit, text, &val);
@@ -196,7 +196,7 @@ class AmountSpinBox: public QAbstractSpinBox
196196
if (text().isEmpty()) // Allow step-up with empty field
197197
return StepUpEnabled;
198198

199-
StepEnabled rv = 0;
199+
StepEnabled rv = StepNone;
200200
bool valid = false;
201201
CAmount val = value(&valid);
202202
if (valid) {
@@ -216,7 +216,7 @@ class AmountSpinBox: public QAbstractSpinBox
216216

217217
BitcoinAmountField::BitcoinAmountField(QWidget *parent) :
218218
QWidget(parent),
219-
amount(0)
219+
amount(nullptr)
220220
{
221221
amount = new AmountSpinBox(this);
222222
amount->setLocale(QLocale::c());

src/qt/bitcoinamountfield.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class BitcoinAmountField: public QWidget
2626
Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY valueChanged USER true)
2727

2828
public:
29-
explicit BitcoinAmountField(QWidget *parent = 0);
29+
explicit BitcoinAmountField(QWidget *parent = nullptr);
3030

31-
CAmount value(bool *value=0) const;
31+
CAmount value(bool *value=nullptr) const;
3232
void setValue(const CAmount& value);
3333

3434
/** If allow empty is set to false the field will be set to the minimum allowed value if left empty. **/

0 commit comments

Comments
 (0)