Merge pull request #1988 from nextcloud/nullptr_everywhere

Use nullptr when appropriate
This commit is contained in:
Michael Schuster 2020-05-20 02:55:15 +02:00 committed by GitHub
commit 1f2bfc0f42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 65 additions and 65 deletions

View file

@ -123,7 +123,7 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout, bool block)
Sleep(DWORD(ms));
#else
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
nanosleep(&ts, NULL);
nanosleep(&ts, nullptr);
#endif
}
if (!connOk)

View file

@ -53,7 +53,7 @@ static QString instancesLockFilename(const QString &appSessionId)
QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
: QApplication(argc, argv),
firstPeer(-1),
pidPeer(0)
pidPeer(nullptr)
{
this->appId = appId;
@ -61,7 +61,7 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char *
// This shared memory holds a zero-terminated array of active (or crashed) instances
instances = new QSharedMemory(appSessionId, this);
actWin = 0;
actWin = nullptr;
block = false;
// First instance creates the shared memory, later instances attach to it
@ -71,7 +71,7 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char *
qWarning() << "Failed to initialize instances shared memory: "
<< instances->errorString();
delete instances;
instances = 0;
instances = nullptr;
return;
}
}

View file

@ -80,7 +80,7 @@ struct CmdOptions
// we can't use csync_set_userdata because the SyncEngine sets it already.
// So we have to use a global variable
CmdOptions *opts = 0;
CmdOptions *opts = nullptr;
class EchoDisabler
{

View file

@ -263,13 +263,13 @@ QByteArray CSyncChecksumHook::hook(const QByteArray &path, const QByteArray &oth
{
QByteArray type = parseChecksumHeaderType(QByteArray(otherChecksumHeader));
if (type.isEmpty())
return NULL;
return nullptr;
qCInfo(lcChecksums) << "Computing" << type << "checksum of" << path << "in the csync hook";
QByteArray checksum = ComputeChecksum::computeNow(QString::fromUtf8(path), type);
if (checksum.isNull()) {
qCWarning(lcChecksums) << "Failed to compute checksum" << type << "for" << path;
return NULL;
return nullptr;
}
return makeChecksumHeader(type, checksum);

View file

@ -44,7 +44,7 @@ namespace OCC {
Q_LOGGING_CATEGORY(lcSql, "nextcloud.sync.database.sql", QtInfoMsg)
SqlDatabase::SqlDatabase()
: _db(0)
: _db(nullptr)
, _errId(0)
{
}
@ -57,7 +57,7 @@ SqlDatabase::~SqlDatabase()
bool SqlDatabase::isOpen()
{
return _db != 0;
return _db != nullptr;
}
bool SqlDatabase::openHelper(const QString &filename, int sqliteFlags)
@ -68,7 +68,7 @@ bool SqlDatabase::openHelper(const QString &filename, int sqliteFlags)
sqliteFlags |= SQLITE_OPEN_NOMUTEX;
SQLITE_DO(sqlite3_open_v2(filename.toUtf8().constData(), &_db, sqliteFlags, 0));
SQLITE_DO(sqlite3_open_v2(filename.toUtf8().constData(), &_db, sqliteFlags, nullptr));
if (_errId != SQLITE_OK) {
qCWarning(lcSql) << "Error:" << _error << "for" << filename;
@ -196,7 +196,7 @@ void SqlDatabase::close()
SQLITE_DO(sqlite3_close(_db));
if (_errId != SQLITE_OK)
qCWarning(lcSql) << "Closing database failed" << _error;
_db = 0;
_db = nullptr;
}
}
@ -205,7 +205,7 @@ bool SqlDatabase::transaction()
if (!_db) {
return false;
}
SQLITE_DO(sqlite3_exec(_db, "BEGIN", 0, 0, 0));
SQLITE_DO(sqlite3_exec(_db, "BEGIN", nullptr, nullptr, nullptr));
return _errId == SQLITE_OK;
}
@ -214,7 +214,7 @@ bool SqlDatabase::commit()
if (!_db) {
return false;
}
SQLITE_DO(sqlite3_exec(_db, "COMMIT", 0, 0, 0));
SQLITE_DO(sqlite3_exec(_db, "COMMIT", nullptr, nullptr, nullptr));
return _errId == SQLITE_OK;
}
@ -255,7 +255,7 @@ int SqlQuery::prepare(const QByteArray &sql, bool allow_failure)
int n = 0;
int rc;
do {
rc = sqlite3_prepare_v2(_db, _sql.constData(), -1, &_stmt, 0);
rc = sqlite3_prepare_v2(_db, _sql.constData(), -1, &_stmt, nullptr);
if ((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED)) {
n++;
OCC::Utility::usleep(SQLITE_SLEEP_TIME_USEC);
@ -462,7 +462,7 @@ void SqlQuery::finish()
if (!_stmt)
return;
SQLITE_DO(sqlite3_finalize(_stmt));
_stmt = 0;
_stmt = nullptr;
if (_sqldb) {
_sqldb->_queries.remove(this);
}

View file

@ -1861,12 +1861,12 @@ QByteArray SyncJournalDb::getChecksumType(int checksumTypeId)
return {};
query.bindValue(1, checksumTypeId);
if (!query.exec()) {
return 0;
return nullptr;
}
if (!query.next()) {
qCWarning(lcDb) << "No checksum type mapping found for" << checksumTypeId;
return 0;
return nullptr;
}
return query.baValue(0);
}

View file

@ -298,7 +298,7 @@ namespace {
QString description(quint64 value) const
{
return QCoreApplication::translate("Utility", name, 0, value);
return QCoreApplication::translate("Utility", name, nullptr, value);
}
};
// QTBUG-3945 and issue #4855: QT_TRANSLATE_NOOP does not work with plural form because lupdate
@ -313,7 +313,7 @@ namespace {
{ QT_TRANSLATE_NOOP("Utility", "%n hour(s)", 0, _), 3600 * 1000LL },
{ QT_TRANSLATE_NOOP("Utility", "%n minute(s)", 0, _), 60 * 1000LL },
{ QT_TRANSLATE_NOOP("Utility", "%n second(s)", 0, _), 1000LL },
{ 0, 0 }
{ nullptr, 0 }
};
} // anonymous namespace
@ -392,7 +392,7 @@ QString Utility::platformName()
void Utility::crash()
{
volatile int *a = (int *)(NULL);
volatile int *a = (int *)nullptr;
*a = 1;
}

View file

@ -67,7 +67,7 @@ csync_s::csync_s(const char *localUri, OCC::SyncJournalDb *statedb)
int csync_update(CSYNC *ctx) {
int rc = -1;
if (ctx == NULL) {
if (ctx == nullptr) {
errno = EBADF;
return -1;
}
@ -188,7 +188,7 @@ static int _csync_treewalk_visitor(csync_file_stat_t *cur, CSYNC * ctx, const cs
other_file_it = other_tree->find(renamed_path);
}
csync_file_stat_t *other = (other_file_it != other_tree->cend()) ? other_file_it->second.get() : NULL;
csync_file_stat_t *other = (other_file_it != other_tree->cend()) ? other_file_it->second.get() : nullptr;
ctx->status_code = CSYNC_STATUS_OK;
@ -256,14 +256,14 @@ csync_s::~csync_s() {
}
void *csync_get_userdata(CSYNC *ctx) {
if (ctx == NULL) {
return NULL;
if (ctx == nullptr) {
return nullptr;
}
return ctx->callbacks.userdata;
}
int csync_set_userdata(CSYNC *ctx, void *userdata) {
if (ctx == NULL) {
if (ctx == nullptr) {
return -1;
}
@ -273,15 +273,15 @@ int csync_set_userdata(CSYNC *ctx, void *userdata) {
}
csync_auth_callback csync_get_auth_callback(CSYNC *ctx) {
if (ctx == NULL) {
return NULL;
if (ctx == nullptr) {
return nullptr;
}
return ctx->callbacks.auth_function;
}
int csync_set_status(CSYNC *ctx, int status) {
if (ctx == NULL || status < 0) {
if (ctx == nullptr || status < 0) {
return -1;
}
@ -291,7 +291,7 @@ int csync_set_status(CSYNC *ctx, int status) {
}
CSYNC_STATUS csync_get_status(CSYNC *ctx) {
if (ctx == NULL) {
if (ctx == nullptr) {
return CSYNC_STATUS_ERROR;
}
@ -305,21 +305,21 @@ const char *csync_get_status_string(CSYNC *ctx)
void csync_request_abort(CSYNC *ctx)
{
if (ctx != NULL) {
if (ctx != nullptr) {
ctx->abort = true;
}
}
void csync_resume(CSYNC *ctx)
{
if (ctx != NULL) {
if (ctx != nullptr) {
ctx->abort = false;
}
}
int csync_abort_requested(CSYNC *ctx)
{
if (ctx != NULL) {
if (ctx != nullptr) {
return ctx->abort;
} else {
return (1 == 0);

View file

@ -133,7 +133,7 @@ bool csync_is_windows_reserved_word(const char *filename)
static CSYNC_EXCLUDE_TYPE _csync_excluded_common(const char *path, bool excludeConflictFiles)
{
const char *bname = NULL;
const char *bname = nullptr;
size_t blen = 0;
int rc = -1;
CSYNC_EXCLUDE_TYPE match = CSYNC_NOT_EXCLUDED;

View file

@ -590,9 +590,9 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
unsigned int depth) {
QByteArray filename;
QByteArray fullpath;
csync_vio_handle_t *dh = NULL;
csync_vio_handle_t *dh = nullptr;
std::unique_ptr<csync_file_stat_t> dirent;
csync_file_stat_t *previous_fs = NULL;
csync_file_stat_t *previous_fs = nullptr;
int read_from_db = 0;
int rc = 0;
@ -625,7 +625,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
return 0;
}
if ((dh = csync_vio_opendir(ctx, uri)) == NULL) {
if ((dh = csync_vio_opendir(ctx, uri)) == nullptr) {
if (ctx->abort) {
qCDebug(lcUpdate, "Aborted!");
ctx->status_code = CSYNC_STATUS_ABORTED;
@ -783,7 +783,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
error:
ctx->remote.read_from_db = read_from_db;
if (dh != NULL) {
if (dh != nullptr) {
csync_vio_closedir(ctx, dh);
}
return -1;

View file

@ -57,7 +57,7 @@ static const _instr_code_struct _instr[] =
{ "INSTRUCTION_ERROR", CSYNC_INSTRUCTION_ERROR },
{ "INSTRUCTION_TYPE_CHANGE", CSYNC_INSTRUCTION_TYPE_CHANGE },
{ "INSTRUCTION_UPDATE_METADATA", CSYNC_INSTRUCTION_UPDATE_METADATA },
{ NULL, CSYNC_INSTRUCTION_ERROR }
{ nullptr, CSYNC_INSTRUCTION_ERROR }
};
struct csync_memstat_s {
@ -74,7 +74,7 @@ const char *csync_instruction_str(enum csync_instructions_e instr)
{
int idx = 0;
while (_instr[idx].instr_str != NULL) {
while (_instr[idx].instr_str != nullptr) {
if (_instr[idx].instr_code == instr) {
return _instr[idx].instr_str;
}
@ -92,7 +92,7 @@ void csync_memstat_check(void) {
/* get process memory stats */
fp = fopen("/proc/self/statm","r");
if (fp == NULL) {
if (fp == nullptr) {
return;
}
s = fscanf(fp, "%d%d%d%d%d%d%d", &m.size, &m.resident, &m.shared, &m.trs,

View file

@ -43,7 +43,7 @@
/* Convert a locale String to UTF8 */
QByteArray c_utf8_from_locale(const mbchar_t *wstr)
{
if (wstr == NULL) {
if (wstr == nullptr) {
return QByteArray();
}
@ -87,8 +87,8 @@ extern "C" {
/* Convert a an UTF8 string to locale */
mbchar_t* c_utf8_string_to_locale(const char *str)
{
if (str == NULL ) {
return NULL;
if (str == nullptr ) {
return nullptr;
}
#ifdef _WIN32
mbchar_t *dst = NULL;
@ -111,8 +111,8 @@ mbchar_t* c_utf8_string_to_locale(const char *str)
mbchar_t* c_utf8_path_to_locale(const char *str)
{
if( str == NULL ) {
return NULL;
if( str == nullptr ) {
return nullptr;
} else {
#ifdef _WIN32
size_t strLength = strlen(str);

View file

@ -47,13 +47,13 @@ csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
default:
ASSERT(false);
}
return NULL;
return nullptr;
}
int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
int rc = -1;
if (dhandle == NULL) {
if (dhandle == nullptr) {
errno = EBADF;
return -1;
}
@ -87,12 +87,12 @@ std::unique_ptr<csync_file_stat_t> csync_vio_readdir(CSYNC *ctx, csync_vio_handl
ASSERT(false);
}
return NULL;
return nullptr;
}
char *csync_vio_get_status_string(CSYNC *ctx) {
if(ctx->error_string) {
return ctx->error_string;
}
return 0;
return nullptr;
}

View file

@ -49,18 +49,18 @@ typedef struct dhandle_s {
static int _csync_vio_local_stat_mb(const mbchar_t *wuri, csync_file_stat_t *buf);
csync_vio_handle_t *csync_vio_local_opendir(const char *name) {
dhandle_t *handle = NULL;
mbchar_t *dirname = NULL;
dhandle_t *handle = nullptr;
mbchar_t *dirname = nullptr;
handle = (dhandle_t*)c_malloc(sizeof(dhandle_t));
dirname = c_utf8_path_to_locale(name);
handle->dh = _topendir( dirname );
if (handle->dh == NULL) {
if (handle->dh == nullptr) {
c_free_locale_string(dirname);
SAFE_FREE(handle);
return NULL;
return nullptr;
}
handle->path = c_strdup(name);
@ -70,10 +70,10 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) {
}
int csync_vio_local_closedir(csync_vio_handle_t *dhandle) {
dhandle_t *handle = NULL;
dhandle_t *handle = nullptr;
int rc = -1;
if (dhandle == NULL) {
if (dhandle == nullptr) {
errno = EBADF;
return -1;
}
@ -89,15 +89,15 @@ int csync_vio_local_closedir(csync_vio_handle_t *dhandle) {
std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *dhandle) {
dhandle_t *handle = NULL;
dhandle_t *handle = nullptr;
handle = (dhandle_t *) dhandle;
struct _tdirent *dirent = NULL;
struct _tdirent *dirent = nullptr;
std::unique_ptr<csync_file_stat_t> file_stat;
do {
dirent = _treaddir(handle->dh);
if (dirent == NULL)
if (dirent == nullptr)
return {};
} while (qstrcmp(dirent->d_name, ".") == 0 || qstrcmp(dirent->d_name, "..") == 0);

View file

@ -362,7 +362,7 @@ void FolderWizardRemotePath::slotFolderEntryEdited(const QString &text)
return;
}
_ui.folderTreeWidget->setCurrentItem(0);
_ui.folderTreeWidget->setCurrentItem(nullptr);
_lscolTimer.start(); // avoid sending a request on each keystroke
}
@ -375,7 +375,7 @@ void FolderWizardRemotePath::slotLsColFolderEntry()
LsColJob *job = runLsColJob(path);
// No error handling, no updating, we do this manually
// because of extra logic in the typed-path case.
disconnect(job, 0, this, 0);
disconnect(job, nullptr, this, nullptr);
connect(job, &LsColJob::finishedWithError,
this, &FolderWizardRemotePath::slotTypedPathError);
connect(job, &LsColJob::directoryListingSubfolders,

View file

@ -101,9 +101,9 @@ void HeaderBanner::setup(const QString &title, const QPixmap &logo, const QPixma
{
QStyle *style = parentWidget()->style();
//const int layoutHorizontalSpacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
int topLevelMarginLeft = style->pixelMetric(QStyle::PM_LayoutLeftMargin, 0, parentWidget());
int topLevelMarginRight = style->pixelMetric(QStyle::PM_LayoutRightMargin, 0, parentWidget());
int topLevelMarginTop = style->pixelMetric(QStyle::PM_LayoutTopMargin, 0, parentWidget());
int topLevelMarginLeft = style->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr, parentWidget());
int topLevelMarginRight = style->pixelMetric(QStyle::PM_LayoutRightMargin, nullptr, parentWidget());
int topLevelMarginTop = style->pixelMetric(QStyle::PM_LayoutTopMargin, nullptr, parentWidget());
//int topLevelMarginBottom = style->pixelMetric(QStyle::PM_LayoutBottomMargin, 0, parentWidget());
layout->setRowMinimumHeight(0, ModernHeaderTopMargin);

View file

@ -144,7 +144,7 @@ WebViewPageUrlSchemeHandler::WebViewPageUrlSchemeHandler(QObject *parent)
void WebViewPageUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request) {
QUrl url = request->requestUrl();
QString path = url.path(0).mid(1); // get undecoded path
QString path = url.path().mid(1); // get undecoded path
const QStringList parts = path.split("&");
QString server;

View file

@ -65,7 +65,7 @@ Logger::Logger(QObject *parent)
Logger::~Logger()
{
#ifndef NO_MSG_HANDLER
qInstallMessageHandler(0);
qInstallMessageHandler(nullptr);
#endif
}