From 2d78034a4bbd3db62510de4738852670a3204e43 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sat, 3 Dec 2022 20:47:45 +0300 Subject: [PATCH 1/2] Fix modernize-use-nullptr warning reported by clang-tidy --- .clang-tidy | 2 +- src/storage/redis_db.cc | 2 +- src/storage/storage.cc | 4 ++-- src/types/geohash.cc | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 5653281be3f..7950de5ff7b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,7 @@ # refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, clang-analyzer-deadcode.*, clang-analyzer-nullability.*, clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, google-build-explicit-make-pair, google-default-arguments, google-explicit-constructor, modernize-avoid-bind, modernize-loop-convert, modernize-macro-to-enum, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, modernize-redundant-void-arg, modernize-return-braced-init-list, modernize-use-auto, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, modernize-use-override, modernize-use-using, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param -WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind, modernize-use-auto, modernize-use-using, performance-inefficient-vector-operation, cppcoreguidelines-special-member-functions, modernize-loop-convert, cppcoreguidelines-init-variables +WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind, modernize-use-auto, modernize-use-using, performance-inefficient-vector-operation, cppcoreguidelines-special-member-functions, modernize-loop-convert, cppcoreguidelines-init-variables, modernize-use-nullptr CheckOptions: - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor diff --git a/src/storage/redis_db.cc b/src/storage/redis_db.cc index a871ef651a3..b80614e02e2 100644 --- a/src/storage/redis_db.cc +++ b/src/storage/redis_db.cc @@ -334,7 +334,7 @@ rocksdb::Status Database::RandomKey(const std::string &cursor, std::string *key) } } if (!keys.empty()) { - unsigned int seed = time(NULL); + unsigned int seed = time(nullptr); *key = keys.at(rand_r(&seed) % keys.size()); } return rocksdb::Status::OK(); diff --git a/src/storage/storage.cc b/src/storage/storage.cc index c45736e9869..b5f38a6774c 100644 --- a/src/storage/storage.cc +++ b/src/storage/storage.cc @@ -338,7 +338,7 @@ Status Storage::CreateBackup() { rocksdb::DestroyDB(tmpdir, rocksdb::Options()); // 1) Create checkpoint of rocksdb for backup - rocksdb::Checkpoint *checkpoint = NULL; + rocksdb::Checkpoint *checkpoint = nullptr; rocksdb::Status s = rocksdb::Checkpoint::Create(db_, &checkpoint); if (!s.ok()) { LOG(WARNING) << "Fail to create checkpoint for backup, error:" << s.ToString(); @@ -731,7 +731,7 @@ Status Storage::ReplDataManager::GetFullReplDataInfo(Storage *storage, std::stri // Create checkpoint if not exist if (!storage->env_->FileExists(data_files_dir).ok()) { - rocksdb::Checkpoint *checkpoint = NULL; + rocksdb::Checkpoint *checkpoint = nullptr; rocksdb::Status s = rocksdb::Checkpoint::Create(storage->db_, &checkpoint); if (!s.ok()) { LOG(WARNING) << "Fail to create checkpoint, error:" << s.ToString(); diff --git a/src/types/geohash.cc b/src/types/geohash.cc index bbfc5256685..ee15617d8f6 100644 --- a/src/types/geohash.cc +++ b/src/types/geohash.cc @@ -166,7 +166,7 @@ void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) { int geohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double longitude, double latitude, uint8_t step, GeoHashBits *hash) { /* Check basic arguments sanity. */ - if (hash == NULL || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0; + if (hash == nullptr || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0; /* Return an error when trying to index outside the supported * constraints. */ @@ -203,7 +203,7 @@ int geohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashB int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, const GeoHashBits &hash, GeoHashArea *area) { - if (HASHISZERO(hash) || NULL == area || RANGEISZERO(lat_range) || RANGEISZERO(long_range)) { + if (HASHISZERO(hash) || nullptr == area || RANGEISZERO(lat_range) || RANGEISZERO(long_range)) { return 0; } From acb433839fa5fcdf8aab6cfb6fc4756d069a7ecf Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sat, 3 Dec 2022 22:04:54 +0300 Subject: [PATCH 2/2] Fix --- src/types/geohash.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/geohash.cc b/src/types/geohash.cc index ee15617d8f6..89d4e0548ed 100644 --- a/src/types/geohash.cc +++ b/src/types/geohash.cc @@ -166,7 +166,7 @@ void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) { int geohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double longitude, double latitude, uint8_t step, GeoHashBits *hash) { /* Check basic arguments sanity. */ - if (hash == nullptr || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0; + if (!hash || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0; /* Return an error when trying to index outside the supported * constraints. */ @@ -203,7 +203,7 @@ int geohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashB int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, const GeoHashBits &hash, GeoHashArea *area) { - if (HASHISZERO(hash) || nullptr == area || RANGEISZERO(lat_range) || RANGEISZERO(long_range)) { + if (HASHISZERO(hash) || !area || RANGEISZERO(lat_range) || RANGEISZERO(long_range)) { return 0; }