From ece0c0a5e7e0b18beb58ccd868bde54c7be64f78 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 22 Nov 2019 14:46:58 +0100 Subject: Tidy nullptr usage Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/corelib/io/qfile.cpp | 4 ++-- src/corelib/io/qfiledevice.cpp | 2 +- src/corelib/io/qfilesystemengine_unix.cpp | 4 ++-- src/corelib/io/qfilesystemwatcher.cpp | 2 +- src/corelib/io/qfilesystemwatcher_inotify.cpp | 2 +- src/corelib/io/qiodevice.cpp | 2 +- src/corelib/io/qnoncontiguousbytedevice.cpp | 20 ++++++++++---------- src/corelib/io/qprocess.cpp | 26 +++++++++++++------------- src/corelib/io/qprocess_unix.cpp | 24 ++++++++++++------------ src/corelib/io/qresource.cpp | 6 +++--- src/corelib/io/qsavefile.cpp | 2 +- src/corelib/io/qsettings.cpp | 12 ++++++------ 12 files changed, 53 insertions(+), 53 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 95f03ef816..5320ae2986 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -251,7 +251,7 @@ QFile::QFile(QFilePrivate &dd) Constructs a QFile object. */ QFile::QFile() - : QFileDevice(*new QFilePrivate, 0) + : QFileDevice(*new QFilePrivate, nullptr) { } /*! @@ -265,7 +265,7 @@ QFile::QFile(QObject *parent) Constructs a new file object to represent the file with the given \a name. */ QFile::QFile(const QString &name) - : QFileDevice(*new QFilePrivate, 0) + : QFileDevice(*new QFilePrivate, nullptr) { Q_D(QFile); d->fileName = name; diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index ee619d99cc..b0aba3193c 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -202,7 +202,7 @@ QFileDevice::QFileDevice(QFileDevicePrivate &dd) \internal */ QFileDevice::QFileDevice() - : QIODevice(*new QFileDevicePrivate, 0) + : QIODevice(*new QFileDevicePrivate, nullptr) { } /*! diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index c3abec8989..2e81f93bcf 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1076,14 +1076,14 @@ bool QFileSystemEngine::cloneFile(int srcfd, int dstfd, const QFileSystemMetaDat // sendfile(2) is limited in the kernel to 2G - 4k const size_t SendfileSize = 0x7ffff000; - ssize_t n = ::sendfile(dstfd, srcfd, NULL, SendfileSize); + ssize_t n = ::sendfile(dstfd, srcfd, nullptr, SendfileSize); if (n == -1) { // if we got an error here, give up and try at an upper layer return false; } while (n) { - n = ::sendfile(dstfd, srcfd, NULL, SendfileSize); + n = ::sendfile(dstfd, srcfd, nullptr, SendfileSize); if (n == -1) { // uh oh, this is probably a real error (like ENOSPC), but we have // no way to notify QFile of partial success, so just erase any work diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 54460aff77..86c8963cb6 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -88,7 +88,7 @@ QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject } QFileSystemWatcherPrivate::QFileSystemWatcherPrivate() - : native(0), poller(0) + : native(nullptr), poller(nullptr) { } diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index ca1f6cc359..888af998a5 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -242,7 +242,7 @@ QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create(QObject if (fd == -1) { fd = inotify_init(); if (fd == -1) - return 0; + return nullptr; } return new QInotifyFileSystemWatcherEngine(fd, parent); } diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index e26508e631..b89cab5e3c 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -461,7 +461,7 @@ QIODevice::QIODevice(QIODevicePrivate &dd) */ QIODevice::QIODevice() - : QObject(*new QIODevicePrivate, 0) + : QObject(*new QIODevicePrivate, nullptr) { #if defined QIODEVICE_DEBUG QFile *file = qobject_cast(this); diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index d1806aa12b..df0197e8eb 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -127,7 +127,7 @@ QT_BEGIN_NAMESPACE \internal */ -QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0) +QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)nullptr) { } @@ -188,7 +188,7 @@ const char* QNonContiguousByteDeviceByteArrayImpl::readPointer(qint64 maximumLen { if (atEnd()) { len = -1; - return 0; + return nullptr; } if (maximumLength != -1) @@ -241,7 +241,7 @@ const char* QNonContiguousByteDeviceRingBufferImpl::readPointer(qint64 maximumLe { if (atEnd()) { len = -1; - return 0; + return nullptr; } const char *returnValue = ringBuffer->readPointerAtPosition(currentPosition, len); @@ -282,7 +282,7 @@ qint64 QNonContiguousByteDeviceRingBufferImpl::size() const QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d) : QNonContiguousByteDevice(), - currentReadBuffer(0), currentReadBufferSize(16*1024), + currentReadBuffer(nullptr), currentReadBufferSize(16*1024), currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0), eof(false) { @@ -301,10 +301,10 @@ const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLeng { if (eof == true) { len = -1; - return 0; + return nullptr; } - if (currentReadBuffer == 0) + if (currentReadBuffer == nullptr) currentReadBuffer = new QByteArray(currentReadBufferSize, '\0'); // lazy alloc if (maximumLength == -1) @@ -323,7 +323,7 @@ const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLeng // size was unknown before, emit a readProgress with the final size if (size() == -1) emit readProgress(totalAdvancements, totalAdvancements); - return 0; + return nullptr; } currentReadBufferAmount = haveRead; @@ -349,7 +349,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) if (currentReadBufferPosition > currentReadBufferAmount) { qint64 i = currentReadBufferPosition - currentReadBufferAmount; while (i > 0) { - if (device->getChar(0) == false) { + if (device->getChar(nullptr) == false) { emit readProgress(totalAdvancements - i, size()); return false; // ### FIXME handle eof } @@ -377,7 +377,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::reset() totalAdvancements = 0; //reset the progress counter if (currentReadBuffer) { delete currentReadBuffer; - currentReadBuffer = 0; + currentReadBuffer = nullptr; } currentReadBufferAmount = 0; currentReadBufferPosition = 0; @@ -405,7 +405,7 @@ qint64 QNonContiguousByteDeviceIoDeviceImpl::pos() const return device->pos(); } -QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)0) +QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)nullptr) { byteDevice = bd; connect(bd, SIGNAL(readyRead()), SIGNAL(readyRead())); diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 35ca2542f7..ad2e7fb6b8 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -216,7 +216,7 @@ void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other) environment variables to be removed. */ QProcessEnvironment::QProcessEnvironment() - : d(0) + : d(nullptr) { } @@ -436,18 +436,18 @@ void QProcessPrivate::Channel::clear() case PipeSource: Q_ASSERT(process); process->stdinChannel.type = Normal; - process->stdinChannel.process = 0; + process->stdinChannel.process = nullptr; break; case PipeSink: Q_ASSERT(process); process->stdoutChannel.type = Normal; - process->stdoutChannel.process = 0; + process->stdoutChannel.process = nullptr; break; } type = Normal; file.clear(); - process = 0; + process = nullptr; } /*! @@ -869,8 +869,8 @@ QProcessPrivate::QProcessPrivate() sequenceNumber = 0; exitCode = 0; exitStatus = QProcess::NormalExit; - startupSocketNotifier = 0; - deathNotifier = 0; + startupSocketNotifier = nullptr; + deathNotifier = nullptr; childStartedPipe[0] = INVALID_Q_PIPE; childStartedPipe[1] = INVALID_Q_PIPE; forkfd = -1; @@ -924,23 +924,23 @@ void QProcessPrivate::cleanup() if (stdoutChannel.notifier) { delete stdoutChannel.notifier; - stdoutChannel.notifier = 0; + stdoutChannel.notifier = nullptr; } if (stderrChannel.notifier) { delete stderrChannel.notifier; - stderrChannel.notifier = 0; + stderrChannel.notifier = nullptr; } if (stdinChannel.notifier) { delete stdinChannel.notifier; - stdinChannel.notifier = 0; + stdinChannel.notifier = nullptr; } if (startupSocketNotifier) { delete startupSocketNotifier; - startupSocketNotifier = 0; + startupSocketNotifier = nullptr; } if (deathNotifier) { delete deathNotifier; - deathNotifier = 0; + deathNotifier = nullptr; } closeChannel(&stdoutChannel); closeChannel(&stderrChannel); @@ -1229,7 +1229,7 @@ void QProcessPrivate::closeWriteChannel() #endif if (stdinChannel.notifier) { delete stdinChannel.notifier; - stdinChannel.notifier = 0; + stdinChannel.notifier = nullptr; } #ifdef Q_OS_WIN // ### Find a better fix, feeding the process little by little @@ -2615,7 +2615,7 @@ QT_END_INCLUDE_NAMESPACE QStringList QProcess::systemEnvironment() { QStringList tmp; - char *entry = 0; + char *entry = nullptr; int count = 0; while ((entry = environ[count++])) tmp << QString::fromLocal8Bit(entry); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 9edb4a6d11..9cd3bd531b 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -338,11 +338,11 @@ static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Map &environme { *envc = 0; if (environment.isEmpty()) - return 0; + return nullptr; char **envp = new char *[environment.count() + 2]; - envp[environment.count()] = 0; - envp[environment.count() + 1] = 0; + envp[environment.count()] = nullptr; + envp[environment.count() + 1] = nullptr; auto it = environment.constBegin(); const auto end = environment.constEnd(); @@ -390,7 +390,7 @@ void QProcessPrivate::startProcess() // Create argument list with right number of elements, and set the final // one to 0. char **argv = new char *[arguments.count() + 2]; - argv[arguments.count() + 1] = 0; + argv[arguments.count() + 1] = nullptr; // Encode the program name. QByteArray encodedProgramName = QFile::encodeName(program); @@ -437,13 +437,13 @@ void QProcessPrivate::startProcess() // Duplicate the environment. int envc = 0; - char **envp = 0; + char **envp = nullptr; if (environment.d.constData()) { envp = _q_dupEnvironment(environment.d.constData()->vars, &envc); } // Encode the working directory if it's non-empty, otherwise just pass 0. - const char *workingDirPtr = 0; + const char *workingDirPtr = nullptr; QByteArray encodedWorkingDirectory; if (!workingDirectory.isEmpty()) { encodedWorkingDirectory = QFile::encodeName(workingDirectory); @@ -596,7 +596,7 @@ bool QProcessPrivate::processStarted(QString *errorMessage) if (startupSocketNotifier) { startupSocketNotifier->setEnabled(false); startupSocketNotifier->deleteLater(); - startupSocketNotifier = 0; + startupSocketNotifier = nullptr; } qt_safe_close(childStartedPipe[0]); childStartedPipe[0] = -1; @@ -889,7 +889,7 @@ bool QProcessPrivate::waitForDeadChild() crashed = info.code != CLD_EXITED; delete deathNotifier; - deathNotifier = 0; + deathNotifier = nullptr; EINTR_LOOP(ret, forkfd_close(forkfd)); forkfd = -1; // Child is dead, don't try to kill it anymore @@ -935,7 +935,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); ::setsid(); @@ -964,7 +964,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) char **argv = new char *[arguments.size() + 2]; for (int i = 0; i < arguments.size(); ++i) argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData()); - argv[arguments.size() + 1] = 0; + argv[arguments.size() + 1] = nullptr; // Duplicate the environment. int envc = 0; @@ -991,7 +991,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); // '\1' means execv failed char c = '\1'; @@ -1002,7 +1002,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); // '\2' means internal error char c = '\2'; diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 0a145b2be4..3664a63050 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -1584,7 +1584,7 @@ QAbstractFileEngine::Iterator *QResourceFileEngine::beginEntryList(QDir::Filters */ QAbstractFileEngine::Iterator *QResourceFileEngine::endEntryList() { - return 0; + return nullptr; } bool QResourceFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) @@ -1594,7 +1594,7 @@ bool QResourceFileEngine::extension(Extension extension, const ExtensionOption * const MapExtensionOption *options = (const MapExtensionOption*)(option); MapExtensionReturn *returnValue = static_cast(output); returnValue->address = d->map(options->offset, options->size, options->flags); - return (returnValue->address != 0); + return (returnValue->address != nullptr); } if (extension == UnMapExtension) { const UnMapExtensionOption *options = (const UnMapExtensionOption*)option; @@ -1623,7 +1623,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory if (offset < 0 || size <= 0 || !resource.isValid() || add_overflow(offset, size, &end) || end > max) { q->setError(QFile::UnspecifiedError, QString()); - return 0; + return nullptr; } const uchar *address = resource.data(); diff --git a/src/corelib/io/qsavefile.cpp b/src/corelib/io/qsavefile.cpp index 0a884a7df9..067ccda3df 100644 --- a/src/corelib/io/qsavefile.cpp +++ b/src/corelib/io/qsavefile.cpp @@ -116,7 +116,7 @@ QSaveFile::QSaveFile(const QString &name) Constructs a new file object to represent the file with the given \a name. */ QSaveFile::QSaveFile(const QString &name) - : QFileDevice(*new QSaveFilePrivate, 0) + : QFileDevice(*new QSaveFilePrivate, nullptr) { Q_D(QSaveFile); d->fileName = name; diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index dcc9340473..9fc45e307d 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -206,7 +206,7 @@ QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) ConfFileHash *usedHash = usedHashFunc(); ConfFileCache *unusedCache = unusedCacheFunc(); - QConfFile *confFile = 0; + QConfFile *confFile = nullptr; const auto locker = qt_scoped_lock(settingsGlobalMutex); if (!(confFile = usedHash->value(absPath))) { @@ -230,7 +230,7 @@ void QConfFile::clearCache() // QSettingsPrivate QSettingsPrivate::QSettingsPrivate(QSettings::Format format) - : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(0), fallbacks(true), + : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(nullptr), fallbacks(true), pendingChanges(false), status(QSettings::NoError) { } @@ -238,7 +238,7 @@ QSettingsPrivate::QSettingsPrivate(QSettings::Format format) QSettingsPrivate::QSettingsPrivate(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application) : format(format), scope(scope), organizationName(organization), applicationName(application), - iniCodec(0), fallbacks(true), pendingChanges(false), status(QSettings::NoError) + iniCodec(nullptr), fallbacks(true), pendingChanges(false), status(QSettings::NoError) { } @@ -924,8 +924,8 @@ QStringList QSettingsPrivate::splitArgs(const QString &s, int idx) void QConfFileSettingsPrivate::initFormat() { extension = (format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"); - readFunc = 0; - writeFunc = 0; + readFunc = nullptr; + writeFunc = nullptr; #if defined(Q_OS_MAC) caseSensitivity = (format == QSettings::NativeFormat) ? Qt::CaseSensitive : IniCaseSensitivity; #else @@ -3338,7 +3338,7 @@ bool QSettings::contains(const QString &key) const { Q_D(const QSettings); QString k = d->actualKey(key); - return d->get(k, 0); + return d->get(k, nullptr); } /*! -- cgit v1.2.3