Skip to content

Commit d028693

Browse files
authored
enable clang-analyzer-* checks in clang-tidy (antgroup#375)
Signed-off-by: Xiangyu Wang <wxy407827@antgroup.com>
1 parent 007b332 commit d028693

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Checks: >
1818
-*,
1919
bugprone-*,
2020
-bugprone-easily-swappable-parameters,
21-
# clang-analyzer-*,
21+
clang-analyzer-*,
22+
-clang-analyzer-deadcode.DeadStores, # value stored but never read
2223
# clang-diagnostic-*,
2324
-clang-diagnostic-deprecated-builtins,
2425
# google-*,

src/factory/factory.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ class LocalFileReader : public Reader {
6666
void
6767
AsyncRead(uint64_t offset, uint64_t len, void* dest, CallBack callback) override {
6868
if (pool_) {
69-
pool_->GeneralEnqueue([this, offset, len, dest, callback]() {
69+
pool_->GeneralEnqueue([this, // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
70+
offset,
71+
len,
72+
dest,
73+
callback]() {
7074
this->Read(offset, len, dest);
7175
callback(IOErrorCode::IO_SUCCESS, "success");
7276
});

src/impl/basic_searcher.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "basic_searcher.h"
1717

18+
#include <limits>
19+
1820
namespace vsag {
1921

2022
BasicSearcher::BasicSearcher(const IndexCommonParam& common_param) {
@@ -65,7 +67,7 @@ BasicSearcher::Search(const GraphInterfacePtr& graph_data_cell,
6567

6668
auto computer = vector_data_cell->FactoryComputer(query);
6769

68-
float lower_bound;
70+
float lower_bound = std::numeric_limits<float>::max();
6971
float dist;
7072
uint64_t candidate_id;
7173
uint32_t hops = 0;

src/index/diskann.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ class LocalMemoryReader : public Reader {
9494
void
9595
AsyncRead(uint64_t offset, uint64_t len, void* dest, CallBack callback) override {
9696
if (pool_) {
97-
pool_->GeneralEnqueue([this, offset, len, dest, callback]() {
97+
pool_->GeneralEnqueue([this, // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
98+
offset,
99+
len,
100+
dest,
101+
callback]() {
98102
this->Read(offset, len, dest);
99103
callback(IOErrorCode::IO_SUCCESS, "success");
100104
});

src/index/diskann_zparameters.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ struct DiskannParameters {
3030

3131
public:
3232
// require vars
33-
int64_t dim;
34-
diskann::Metric metric;
35-
int64_t max_degree;
36-
int64_t ef_construction;
37-
int64_t pq_dims;
38-
float pq_sample_rate;
33+
int64_t dim{-1};
34+
diskann::Metric metric{diskann::Metric::L2};
35+
int64_t max_degree{-1};
36+
int64_t ef_construction{-1};
37+
int64_t pq_dims{-1};
38+
float pq_sample_rate{.0f};
3939

4040
// optional vars with default value
4141
bool use_preload = false;
@@ -61,9 +61,9 @@ struct DiskannSearchParameters {
6161

6262
public:
6363
// required vars
64-
int64_t ef_search;
65-
uint64_t beam_search;
66-
int64_t io_limit;
64+
int64_t ef_search{-1};
65+
uint64_t beam_search{0};
66+
int64_t io_limit{-1};
6767

6868
// optional vars with default value
6969
bool use_reorder = false;

src/index/hnsw_zparameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct HnswParameters {
3838
bool use_static{false};
3939
bool normalize{false};
4040
bool use_reversed_edges{false};
41-
DataTypes type;
41+
DataTypes type{DataTypes::DATA_TYPE_FLOAT};
4242

4343
protected:
4444
HnswParameters() = default;

src/io/memory_io_parameter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MemoryIOParameter::MemoryIOParameter() : IOParameter(IO_TYPE_VALUE_MEMORY_IO) {
2424

2525
MemoryIOParameter::MemoryIOParameter(const vsag::JsonType& json)
2626
: IOParameter(IO_TYPE_VALUE_MEMORY_IO) {
27-
this->FromJson(json);
27+
this->FromJson(json); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall)
2828
}
2929

3030
void

src/safe_thread_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SafeThreadPool : public ThreadPool {
4848

4949
std::future<return_type> res = task->get_future();
5050
Enqueue([task]() { (*task)(); });
51-
return res;
51+
return res; // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
5252
}
5353

5454
std::future<void>

0 commit comments

Comments
 (0)