Use nullptr when appropriate
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 18 May 2020 18:39:16 +0000 (20:39 +0200)
committerMichael Schuster <michael@schuster.ms>
Wed, 20 May 2020 00:21:26 +0000 (02:21 +0200)
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
18 files changed:
src/3rdparty/qtsingleapplication/qtlocalpeer.cpp
src/3rdparty/qtsingleapplication/qtsingleapplication.cpp
src/cmd/cmd.cpp
src/common/checksums.cpp
src/common/ownsql.cpp
src/common/syncjournaldb.cpp
src/common/utility.cpp
src/csync/csync.cpp
src/csync/csync_exclude.cpp
src/csync/csync_update.cpp
src/csync/csync_util.cpp
src/csync/std/c_utf8.cpp
src/csync/vio/csync_vio.cpp
src/csync/vio/csync_vio_local_unix.cpp
src/gui/folderwizard.cpp
src/gui/headerbanner.cpp
src/gui/wizard/webview.cpp
src/libsync/logger.cpp

index 3ebba6e6fd430f76ed763f6eaa5aa3005c893ad0..f7229df5afc9fc0a4097b821e6f2aa07939e2dea 100644 (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)
index 844824cb477e60650c5eada3c529f583b0e974ce..5934d1cb38de56aa3a458207af2c4aef59c066f5 100644 (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;
         }
     }
index 47876b2313ba8cbd0344bceb93d13e0024e69743..290c496a1c4815cb780d119cd09a7a9271bc81de 100644 (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
 {
index 6edf84de90fd57b250a27ccecf005c9c248bfeb1..566c84ad7de7080dfcfc124d88a802c38cd75572 100644 (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);
index b82808d86ac4aa8e747dae0e6d5842825d255ded..6aa3649c1db23133f44ce565e2b0101d1bb51a1f 100644 (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);
     }
index e4078efd9b3f2d621190e3aaef41d6f8e29600ec..412b21810f80241a0bb6657e544c964062ffa58b 100644 (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);
 }
index 8229cab0579ea5b39ea1f0aabc964911106281f4..49503231207dd4a1f62807eba68cb4bb425b698f 100644 (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;
 }
 
index 8507398ec14bdc122d4ed28c46ca41e7a8c77dfd..caee4146df28a60ff2545fab548fea32080b7377 100644 (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);
index 169a88e002bcc8a2e6ef3de9b13e8bb2b0bac18c..d20e8f49d3db690f1781a07b303ff2b9b681c08d 100644 (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;
index 45a65f219412910f6c1ab07898c84182444c9198..f7320d9bd01258d2516174a574332e11107a9f9b 100644 (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;
index 761537bb8dd1f8582fab65e2c666984bd45b465e..c8908bb82d17a7c295220fb2396bf394c84dc0d1 100644 (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,
index 778486e8b183d0f41f2685bae68b7aac02148d8c..fe3b8ca20dceea7174b7a02b4ab949ac24764c8d 100644 (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);
index 2975b560d3cc2dd6ef73ad75054dc5fdaaf30603..1d5e6f61023d7dad7749603e8f88ebae827e5bf6 100644 (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;
 }
index f2620bbb62c6cb209b45cfe2fc0881e5027cd63d..addfd6ed28e60c009fdeb38fcbd9b348ed48e109 100644 (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);
 
index 324503a4b2043127a083e1ec2d9454aa5c18438d..fce3dcf7fafe2fcfe23bf31ccff2a3eb30f8019e 100644 (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,
index 4c425750ff1ac495aa598d36b30b7ae5a8917e01..912cf9a7232be096571bdfd5716abb55d75ff899 100644 (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);
index 6603820f4f33bab959ca0093ab63d4e197d01bcd..d6c583fb9f1047ca2b7e554eec4b35e7cd3a1d00 100644 (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(nullptr).mid(1); // get undecoded path
     const QStringList parts = path.split("&");
 
     QString server;
index fb83259e5cd03985c60de954c7ff699e9848910e..c4d294aecad0cc2d97085a071533c7cb9582be7d 100644 (file)
@@ -65,7 +65,7 @@ Logger::Logger(QObject *parent)
 Logger::~Logger()
 {
 #ifndef NO_MSG_HANDLER
-    qInstallMessageHandler(0);
+    qInstallMessageHandler(nullptr);
 #endif
 }