Improve readability and type-safety

Use nullptr instead of 0 or NULL to initialize a null pointer. In some
cases, readability was enhanced by replacing 0 with more meaningful
values according to the type of the pointer being initialized.
This commit is contained in:
Gianluca Recchia 2018-10-28 15:47:24 +01:00
parent 7208635502
commit 896a66e6d8
No known key found for this signature in database
GPG Key ID: 3C2B4128D9A1F218
22 changed files with 47 additions and 47 deletions

View File

@ -43,7 +43,7 @@ AutoType::AutoType(QObject* parent, bool test)
: QObject(parent)
, m_autoTypeDelay(0)
, m_currentGlobalKey(static_cast<Qt::Key>(0))
, m_currentGlobalModifiers(0)
, m_currentGlobalModifiers(nullptr)
, m_pluginLoader(new QPluginLoader(this))
, m_plugin(nullptr)
, m_executor(nullptr)

View File

@ -24,7 +24,7 @@
ShortcutWidget::ShortcutWidget(QWidget* parent)
: QLineEdit(parent)
, m_key(static_cast<Qt::Key>(0))
, m_modifiers(0)
, m_modifiers(nullptr)
, m_locked(false)
{
setReadOnly(true);
@ -58,7 +58,7 @@ void ShortcutWidget::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers)
void ShortcutWidget::resetShortcut()
{
m_key = static_cast<Qt::Key>(0);
m_modifiers = 0;
m_modifiers = nullptr;
m_locked = false;
autoType()->unregisterGlobalShortcut();
}

View File

@ -50,7 +50,7 @@ AutoTypePlatformX11::AutoTypePlatformX11()
<< "xfce4-panel"; // Xfce 4
m_currentGlobalKey = static_cast<Qt::Key>(0);
m_currentGlobalModifiers = 0;
m_currentGlobalModifiers = nullptr;
m_keysymTable = nullptr;
m_xkb = nullptr;
@ -197,7 +197,7 @@ void AutoTypePlatformX11::unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModi
XUngrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow);
m_currentGlobalKey = static_cast<Qt::Key>(0);
m_currentGlobalModifiers = 0;
m_currentGlobalModifiers = nullptr;
m_currentGlobalKeycode = 0;
m_currentGlobalNativeModifiers = 0;
}
@ -496,7 +496,7 @@ void AutoTypePlatformX11::updateKeymap()
m_xkb = getKeyboard();
XDisplayKeycodes(m_dpy, &m_minKeycode, &m_maxKeycode);
if (m_keysymTable != NULL)
if (m_keysymTable != nullptr)
XFree(m_keysymTable);
m_keysymTable = XGetKeyboardMapping(m_dpy, m_minKeycode, m_maxKeycode - m_minKeycode + 1, &m_keysymPerKeycode);

View File

@ -35,7 +35,7 @@ class BrowserEntryConfig : public QObject
Q_PROPERTY(QString Realm READ realm WRITE setRealm)
public:
BrowserEntryConfig(QObject* object = 0);
BrowserEntryConfig(QObject* object = nullptr);
bool load(const Entry* entry);
void save(Entry* entry);

View File

@ -481,16 +481,16 @@ void BrowserService::convertAttributesToCustomData(Database *currentDb)
progress.reset();
if (counter > 0) {
QMessageBox::information(0, tr("KeePassXC: Converted KeePassHTTP attributes"),
QMessageBox::information(nullptr, tr("KeePassXC: Converted KeePassHTTP attributes"),
tr("Successfully converted attributes from %1 entry(s).\n"
"Moved %2 keys to custom data.", "").arg(counter).arg(keyCounter),
QMessageBox::Ok);
} else if (counter == 0 && keyCounter > 0) {
QMessageBox::information(0, tr("KeePassXC: Converted KeePassHTTP attributes"),
QMessageBox::information(nullptr, tr("KeePassXC: Converted KeePassHTTP attributes"),
tr("Successfully moved %n keys to custom data.", "", keyCounter),
QMessageBox::Ok);
} else {
QMessageBox::information(0, tr("KeePassXC: No entry with KeePassHTTP attributes found!"),
QMessageBox::information(nullptr, tr("KeePassXC: No entry with KeePassHTTP attributes found!"),
tr("The active database does not contain an entry with KeePassHTTP attributes."),
QMessageBox::Ok);
}

View File

@ -111,7 +111,7 @@ void HostInstaller::installBrowser(SupportedBrowsers browser,
// Always create the script file
QJsonObject script = constructFile(browser, proxy, location);
if (!saveFile(browser, script)) {
QMessageBox::critical(0,
QMessageBox::critical(nullptr,
tr("KeePassXC: Cannot save file!"),
tr("Cannot save the native messaging script file."),
QMessageBox::Ok);

View File

@ -31,7 +31,7 @@ class NativeMessagingHost : public NativeMessagingBase
typedef QList<QLocalSocket*> SocketList;
public:
explicit NativeMessagingHost(DatabaseTabWidget* parent = 0, const bool enabled = false);
explicit NativeMessagingHost(DatabaseTabWidget* parent = nullptr, const bool enabled = false);
~NativeMessagingHost();
int init();
void run();

View File

@ -25,15 +25,15 @@ const char* PasswordGenerator::DefaultExcludedChars = "";
PasswordGenerator::PasswordGenerator()
: m_length(0)
, m_classes(0)
, m_flags(0)
, m_classes(nullptr)
, m_flags(nullptr)
, m_excluded(PasswordGenerator::DefaultExcludedChars)
{
}
double PasswordGenerator::calculateEntropy(const QString& password)
{
return ZxcvbnMatch(password.toLatin1(), 0, 0);
return ZxcvbnMatch(password.toLatin1(), nullptr, nullptr);
}
void PasswordGenerator::setLength(int length)

View File

@ -24,10 +24,10 @@ class ScreenLockListenerPrivate : public QObject
{
Q_OBJECT
public:
static ScreenLockListenerPrivate* instance(QWidget* parent = 0);
static ScreenLockListenerPrivate* instance(QWidget* parent = nullptr);
protected:
ScreenLockListenerPrivate(QWidget* parent = 0);
ScreenLockListenerPrivate(QWidget* parent = nullptr);
signals:
void screenLocked();

View File

@ -27,7 +27,7 @@ class ScreenLockListenerWin : public ScreenLockListenerPrivate, public QAbstract
{
Q_OBJECT
public:
explicit ScreenLockListenerWin(QWidget* parent = 0);
explicit ScreenLockListenerWin(QWidget* parent = nullptr);
~ScreenLockListenerWin();
virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long*) override;

View File

@ -336,4 +336,4 @@ bool Crypto::testChaCha20()
}
return true;
}
}

View File

@ -35,7 +35,7 @@ class CategoryListWidget : public QWidget
Q_OBJECT
public:
CategoryListWidget(QWidget* parent = 0);
CategoryListWidget(QWidget* parent = nullptr);
~CategoryListWidget();
int currentCategory();
@ -90,4 +90,4 @@ private:
Q_DISABLE_COPY(CategoryListWidgetDelegate)
};
#endif
#endif

View File

@ -122,7 +122,7 @@ void DatabaseOpenWidget::hideEvent(QHideEvent* event)
#ifdef WITH_XC_YUBIKEY
// Don't listen to any Yubikey events if we are hidden
disconnect(YubiKey::instance(), 0, this, 0);
disconnect(YubiKey::instance(), nullptr, this, nullptr);
m_yubiKeyBeingPolled = false;
#endif
}

View File

@ -419,7 +419,7 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
oldFilePath,
tr("KeePass 2 Database").append(" (*.kdbx)"),
nullptr,
0,
nullptr,
"kdbx");
if (!newFilePath.isEmpty()) {
// Ensure we don't recurse back into this function
@ -488,7 +488,7 @@ void DatabaseTabWidget::exportToCsv()
}
QString fileName = fileDialog()->getSaveFileName(
this, tr("Export database to CSV file"), QString(), tr("CSV file").append(" (*.csv)"), nullptr, 0, "csv");
this, tr("Export database to CSV file"), QString(), tr("CSV file").append(" (*.csv)"), nullptr, nullptr, "csv");
if (fileName.isEmpty()) {
return;
}

View File

@ -411,7 +411,7 @@ void KMessageWidget::removeAction(QAction *action)
void KMessageWidget::animatedShow()
{
if (!style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) {
if (!style()->styleHint(QStyle::SH_Widget_Animate, nullptr, this)) {
show();
emit showAnimationFinished();
return;
@ -436,7 +436,7 @@ void KMessageWidget::animatedShow()
void KMessageWidget::animatedHide()
{
if (!style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) {
if (!style()->styleHint(QStyle::SH_Widget_Animate, nullptr, this)) {
hide();
emit hideAnimationFinished();
return;

View File

@ -28,7 +28,7 @@ class MessageWidget : public KMessageWidget
Q_OBJECT
public:
explicit MessageWidget(QWidget* parent = 0);
explicit MessageWidget(QWidget* parent = nullptr);
int autoHideTimeout() const;

View File

@ -35,7 +35,7 @@ class SearchWidget : public QWidget
Q_OBJECT
public:
explicit SearchWidget(QWidget* parent = 0);
explicit SearchWidget(QWidget* parent = nullptr);
~SearchWidget();
void connectSignals(SignalMultiplexer& mx);
@ -55,7 +55,7 @@ signals:
void enterPressed();
public slots:
void databaseChanged(DatabaseWidget* dbWidget = 0);
void databaseChanged(DatabaseWidget* dbWidget = nullptr);
private slots:
void startSearchTimer();

View File

@ -1269,13 +1269,13 @@ QMenu* EditEntryWidget::createPresetsMenu()
QMenu* expirePresetsMenu = new QMenu(this);
expirePresetsMenu->addAction(tr("Tomorrow"))->setData(QVariant::fromValue(TimeDelta::fromDays(1)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("%n week(s)", 0, 1))->setData(QVariant::fromValue(TimeDelta::fromDays(7)));
expirePresetsMenu->addAction(tr("%n week(s)", 0, 2))->setData(QVariant::fromValue(TimeDelta::fromDays(14)));
expirePresetsMenu->addAction(tr("%n week(s)", 0, 3))->setData(QVariant::fromValue(TimeDelta::fromDays(21)));
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 1))->setData(QVariant::fromValue(TimeDelta::fromDays(7)));
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 2))->setData(QVariant::fromValue(TimeDelta::fromDays(14)));
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 3))->setData(QVariant::fromValue(TimeDelta::fromDays(21)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("%n month(s)", 0, 1))->setData(QVariant::fromValue(TimeDelta::fromMonths(1)));
expirePresetsMenu->addAction(tr("%n month(s)", 0, 3))->setData(QVariant::fromValue(TimeDelta::fromMonths(3)));
expirePresetsMenu->addAction(tr("%n month(s)", 0, 6))->setData(QVariant::fromValue(TimeDelta::fromMonths(6)));
expirePresetsMenu->addAction(tr("%n month(s)", nullptr, 1))->setData(QVariant::fromValue(TimeDelta::fromMonths(1)));
expirePresetsMenu->addAction(tr("%n month(s)", nullptr, 3))->setData(QVariant::fromValue(TimeDelta::fromMonths(3)));
expirePresetsMenu->addAction(tr("%n month(s)", nullptr, 6))->setData(QVariant::fromValue(TimeDelta::fromMonths(6)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("%n year(s)", 0, 1))->setData(QVariant::fromValue(TimeDelta::fromYears(1)));
expirePresetsMenu->addAction(tr("%n year(s)", 0, 2))->setData(QVariant::fromValue(TimeDelta::fromYears(2)));

View File

@ -24,7 +24,7 @@
class AttributesListView : public QListView
{
public:
explicit AttributesListView(QWidget* parent = 0)
explicit AttributesListView(QWidget* parent = nullptr)
: QListView(parent)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);

View File

@ -331,7 +331,7 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
Qt::DropActions EntryModel::supportedDropActions() const
{
return 0;
return Qt::IgnoreAction;
}
Qt::DropActions EntryModel::supportedDragActions() const

View File

@ -37,8 +37,8 @@
#define m_ykds (static_cast<YK_STATUS*>(m_ykds_void))
YubiKey::YubiKey()
: m_yk_void(NULL)
, m_ykds_void(NULL)
: m_yk_void(nullptr)
, m_ykds_void(nullptr)
, m_mutex(QMutex::Recursive)
{
}
@ -59,7 +59,7 @@ bool YubiKey::init()
m_mutex.lock();
// previously initialized
if (m_yk != NULL && m_ykds != NULL) {
if (m_yk != nullptr && m_ykds != nullptr) {
if (yk_get_status(m_yk, m_ykds)) {
// Still connected
@ -78,15 +78,15 @@ bool YubiKey::init()
// TODO: handle multiple attached hardware devices
m_yk_void = static_cast<void*>(yk_open_first_key());
if (m_yk == NULL) {
if (m_yk == nullptr) {
m_mutex.unlock();
return false;
}
m_ykds_void = static_cast<void*>(ykds_alloc());
if (m_ykds == NULL) {
if (m_ykds == nullptr) {
yk_close_key(m_yk);
m_yk_void = NULL;
m_yk_void = nullptr;
m_mutex.unlock();
return false;
}
@ -101,12 +101,12 @@ bool YubiKey::deinit()
if (m_yk) {
yk_close_key(m_yk);
m_yk_void = NULL;
m_yk_void = nullptr;
}
if (m_ykds) {
ykds_free(m_ykds);
m_ykds_void = NULL;
m_ykds_void = nullptr;
}
m_mutex.unlock();

View File

@ -116,7 +116,7 @@ QtIOCompressorPrivate::~QtIOCompressorPrivate()
void QtIOCompressorPrivate::flushZlib(int flushMode)
{
// No input.
zlibStream.next_in = 0;
zlibStream.next_in = nullptr;
zlibStream.avail_in = 0;
int status;
do {
@ -387,7 +387,7 @@ bool QtIOCompressor::open(OpenMode mode)
if (read) {
d->state = QtIOCompressorPrivate::NotReadFirstByte;
d->zlibStream.avail_in = 0;
d->zlibStream.next_in = 0;
d->zlibStream.next_in = nullptr;
if (d->streamFormat == QtIOCompressor::ZlibFormat) {
status = inflateInit(&d->zlibStream);
} else {