feat(ci): integrate clang-tidy for changed C/C++ files (#116)

* feat(ci): add clang-tidy checks for changed cpp files

* fix(ci): correct clang-tidy workflow heredoc indentation

* test: stabilize fp16 euclidean matrix comparison

* test: fix fp16 matrix CI and clang-tidy warnings

* ci: scope clang-tidy PR and filter compile-db files

* check nullptr only

* fix nullptr

* fix: format

* chore: ignore c

* fix: tests files

* fix: workflow

* fix: specify clang-tidy version

* fix: filter regex

* fix: more files

* fix: update version

* add thirdparty cache

* add pipeline dependency

* fix clang-tidy trigger

---------

Co-authored-by: kgeg401 <kgeg401@users.noreply.github.com>
Co-authored-by: jiliang.ljl <jiliang.ljl@alibaba-inc.com>
This commit is contained in:
kgeg401
2026-04-20 20:14:21 +08:00
committed by GitHub
co-authored by kgeg401 jiliang.ljl
parent c17bd8876e
commit 1e25294c07
21 changed files with 300 additions and 122 deletions
+7
View File
@@ -0,0 +1,7 @@
Checks: >
-*,
modernize-use-nullptr,
WarningsAsErrors: "*"
HeaderFilterRegex: "^(src|tests|tools)/"
FormatStyle: none
SystemHeaders: false
+16 -8
View File
@@ -42,10 +42,18 @@ jobs:
!contains(github.event.pull_request.title, 'wip'))
uses: ./.github/workflows/02-lint-check.yml
# Static analysis: clang-tidy on changed C/C++ files
clang-tidy:
if: >-
github.event_name != 'pull_request' ||
(!github.event.pull_request.draft &&
!contains(github.event.pull_request.title, 'wip'))
uses: ./.github/workflows/clang_tidy.yml
# Main build and test matrix
build-and-test-macos-arm64:
name: Build & Test (macos-arm64)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/03-macos-linux-build.yml
with:
platform: macos-arm64
@@ -53,7 +61,7 @@ jobs:
build-and-test-macos-26-arm64:
name: Build & Test (macos-26-arm64)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/03-macos-linux-build.yml
with:
platform: macos-arm64
@@ -61,7 +69,7 @@ jobs:
build-and-test-linux-arm64:
name: Build & Test (linux-arm64)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/03-macos-linux-build.yml
with:
platform: linux-arm64
@@ -69,7 +77,7 @@ jobs:
build-and-test-linux-x64:
name: Build & Test (linux-x64)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/03-macos-linux-build.yml
with:
platform: linux-x64
@@ -77,7 +85,7 @@ jobs:
build-and-test-linux-x64-clang:
name: Build & Test (linux-x64-clang)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/03-macos-linux-build.yml
with:
platform: linux-x64-clang
@@ -86,15 +94,15 @@ jobs:
build-android:
name: Build & Test (android)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/04-android-build.yml
build-and-test-on-windows:
name: Build & Test (Windows)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/05-windows-build.yml
build-ios:
name: Build & Test (iOS)
needs: lint
needs: [lint, clang-tidy]
uses: ./.github/workflows/06-ios-build.yml
+156
View File
@@ -0,0 +1,156 @@
name: Clang-Tidy
on:
workflow_call:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
clang_tidy:
name: Clang-Tidy Checks
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
submodules: recursive
# fetch-depth: 0 is required for tj-actions/changed-files to correctly
# compute the diff against the base branch on pull_request events.
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy=1:18.0-59~exp2 cmake ninja-build
- name: Configure CMake and export compile commands
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DBUILD_TOOLS=ON
- name: Collect changed C/C++ files
id: changed_files
uses: tj-actions/changed-files@v47
with:
files: |
**/*.c
**/*.cc
**/*.cpp
**/*.cxx
files_ignore: |
thirdparty/**
build/**
- name: Filter changed files against compile_commands.json
id: tidy_files
if: steps.changed_files.outputs.any_changed == 'true'
run: |
python3 - <<'PY'
import json
import os
from pathlib import Path
# all_changed_files is space-separated when output_format is not set;
# tj-actions v46 defaults to space-separated for the env var form.
# We read from the file written by the action instead via GITHUB_OUTPUT,
# but the safest approach is to use the JSON output format.
raw = os.environ.get("ALL_CHANGED_FILES", "")
changed = [f for f in raw.split() if f]
compile_db_path = Path("build/compile_commands.json")
with compile_db_path.open("r", encoding="utf-8") as fh:
compile_db = json.load(fh)
# Build a set of absolute, normalised paths from compile_commands.json.
compile_entries = set()
for entry in compile_db:
file_field = entry.get("file", "")
if file_field:
compile_entries.add(os.path.normpath(file_field))
cwd = Path.cwd().resolve()
selected = []
skipped = []
for rel_path in changed:
abs_path = os.path.normpath(str((cwd / rel_path).resolve()))
if abs_path in compile_entries:
selected.append(rel_path)
elif not Path(rel_path).is_file():
skipped.append(f"{rel_path} (file not found)")
else:
skipped.append(f"{rel_path} (not in compile_commands.json)")
github_output = os.environ["GITHUB_OUTPUT"]
with open(github_output, "a", encoding="utf-8") as out:
out.write(f"any_tidy_files={'true' if selected else 'false'}\n")
out.write("all_tidy_files<<TIDY_EOF\n")
out.write("\n".join(selected) + "\n")
out.write("TIDY_EOF\n")
out.write("skipped_files<<SKIP_EOF\n")
out.write("\n".join(skipped) + "\n")
out.write("SKIP_EOF\n")
PY
env:
ALL_CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
- name: Show skipped files
if: steps.changed_files.outputs.any_changed == 'true' && steps.tidy_files.outputs.skipped_files != ''
run: |
echo "=== Files skipped by clang-tidy ==="
printf '%s\n' "${{ steps.tidy_files.outputs.skipped_files }}"
- name: Compute submodule commits hash
id: submodule_hash
run: |
# Collect each submodule's current commit SHA, sort for a stable order,
# then SHA-256 the result so the cache key stays a fixed length.
hash=$(git submodule status --recursive | awk '{print $1}' | sort | sha256sum | awk '{print $1}')
echo "value=${hash}" >> "$GITHUB_OUTPUT"
- name: Cache third-party build artifacts
id: cache_thirdparty
uses: actions/cache@v5
with:
path: build/external
# Cache key combines:
# - thirdparty CMakeLists / cmake / patch file contents
# - all submodule commit SHAs (upgrading a submodule busts the cache)
key: thirdparty-${{ runner.os }}-${{ hashFiles('thirdparty/**/*.cmake', 'thirdparty/**/CMakeLists.txt', 'thirdparty/**/*.patch') }}-${{ steps.submodule_hash.outputs.value }}
- name: Build
if: steps.tidy_files.outputs.any_tidy_files == 'true'
run: |
# build so that clang-tidy can find the headers
ninja -C build zvec_db
- name: Run clang-tidy on changed files
if: steps.tidy_files.outputs.any_tidy_files == 'true'
run: |
# Read the newline-delimited file list into an array.
mapfile -t files_to_check <<'TIDY_EOF'
${{ steps.tidy_files.outputs.all_tidy_files }}
TIDY_EOF
failed=0
for file in "${files_to_check[@]}"; do
# Skip blank lines that mapfile may produce.
[[ -z "${file// }" ]] && continue
if [ -f "$file" ]; then
echo "=== clang-tidy: $file ==="
clang-tidy -p build --warnings-as-errors='*' "$file" || failed=1
fi
done
exit $failed
- name: No C/C++ files changed
if: steps.changed_files.outputs.any_changed != 'true' || steps.tidy_files.outputs.any_tidy_files != 'true'
run: echo "No changed source files with compile_commands entries to analyse."
+1
View File
@@ -17,6 +17,7 @@ tests/de_integration/log
tests/de_integration/*.log
!.git*
!.clang-format
!.clang-tidy
!.circleci
!.drone.yml
sdk/python/dist/
+10 -10
View File
@@ -88,7 +88,7 @@ void Bitmap::copy(const Bitmap &rhs) {
for (std::vector<Bucket *>::const_iterator iter = rhs.array_.begin();
iter != rhs.array_.end(); ++iter) {
Bucket *bucket = NULL;
Bucket *bucket = nullptr;
if (*iter) {
bucket = new Bucket(*(*iter));
}
@@ -106,14 +106,14 @@ void Bitmap::shrink_to_fit(void) {
break;
}
delete (*iter);
*iter = NULL;
*iter = nullptr;
}
++shrink_count;
}
for (; iter != array_.rend(); ++iter) {
if ((*iter) && (*iter)->test_none()) {
delete (*iter);
*iter = NULL;
*iter = nullptr;
}
}
if (shrink_count != 0) {
@@ -139,7 +139,7 @@ void Bitmap::set(size_t num) {
// High 16 bits
size_t offset = num >> 16;
if (offset >= array_.size()) {
array_.resize(offset + 1, NULL);
array_.resize(offset + 1, nullptr);
}
Bucket *&bucket = array_[offset];
@@ -154,7 +154,7 @@ void Bitmap::reset(size_t num) {
// High 16 bits
size_t offset = num >> 16;
if (offset >= array_.size()) {
array_.resize(offset + 1, NULL);
array_.resize(offset + 1, nullptr);
}
if (offset < array_.size()) {
@@ -170,7 +170,7 @@ void Bitmap::flip(size_t num) {
// High 16 bits
uint16_t offset = (uint16_t)(num >> 16);
if (offset >= array_.size()) {
array_.resize(offset + 1, NULL);
array_.resize(offset + 1, nullptr);
}
Bucket *&bucket = array_[offset];
@@ -193,14 +193,14 @@ void Bitmap::bitwise_and(const Bitmap &rhs) {
dst->bitwise_and(*src);
} else {
delete dst;
dst = NULL;
dst = nullptr;
}
}
}
for (size_t i = overlap; i < array_.size(); ++i) {
Bucket *&dst = array_[i];
delete dst;
dst = NULL;
dst = nullptr;
}
}
@@ -237,7 +237,7 @@ void Bitmap::bitwise_or(const Bitmap &rhs) {
}
for (size_t i = overlap; i < rhs.array_.size(); ++i) {
const Bucket *src = rhs.array_[i];
Bucket *bucket = NULL;
Bucket *bucket = nullptr;
if (src) {
bucket = new Bucket(*src);
@@ -264,7 +264,7 @@ void Bitmap::bitwise_xor(const Bitmap &rhs) {
}
for (size_t i = overlap; i < rhs.array_.size(); ++i) {
const Bucket *src = rhs.array_[i];
Bucket *bucket = NULL;
Bucket *bucket = nullptr;
if (src) {
bucket = new Bucket(*src);
+1 -1
View File
@@ -57,7 +57,7 @@ CpuFeatures::CpuFlags::CpuFlags(void)
L1_ECX = ecx;
L1_EDX = edx;
}
if (__get_cpuid_max(0, NULL) >= 7) {
if (__get_cpuid_max(0, nullptr) >= 7) {
__cpuid_count(7, 0, eax, ebx, ecx, edx);
L7_EBX = ebx;
L7_ECX = ecx;
+10 -10
View File
@@ -89,7 +89,7 @@ size_t MemoryHelper::AvailableRamSize(void) {
char buf[128];
while (fgets(buf, sizeof(buf), fp)) {
if (strncmp(buf, "MemAvailable:", 13) == 0) {
avail = (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail = (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
break;
}
}
@@ -103,21 +103,21 @@ size_t MemoryHelper::AvailableRamSize(void) {
switch (buf[0]) {
case 'M':
if (strncmp(buf, "MemFree:", 8) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
case 'B':
if (strncmp(buf, "Buffers:", 8) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
case 'C':
if (strncmp(buf, "Cached:", 7) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
@@ -145,31 +145,31 @@ size_t MemoryHelper::UsedRamSize(void) {
switch (buf[0]) {
case 'M':
if (strncmp(buf, "MemTotal:", 9) == 0) {
total = (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
total = (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
} else if (strncmp(buf, "MemFree:", 8) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
case 'B':
if (strncmp(buf, "Buffers:", 8) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
case 'C':
if (strncmp(buf, "Cached:", 7) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
case 'S':
if (strncmp(buf, "Slab:", 5) == 0) {
avail += (size_t)strtoull(strchr(buf, ':') + 1, NULL, 10);
avail += (size_t)strtoull(strchr(buf, ':') + 1, nullptr, 10);
++count;
}
break;
@@ -253,7 +253,7 @@ size_t MemoryHelper::TotalRamSize(void) {
int mib[2] = {CTL_HW, HW_MEMSIZE};
uint64_t size = 0;
size_t len = sizeof(size);
if (sysctl(mib, 2, &size, &len, 0, 0) != 0) {
if (sysctl(mib, 2, &size, &len, nullptr, 0) != 0) {
return 0;
}
return (size_t)size;
+2 -2
View File
@@ -176,13 +176,13 @@ size_t Realtime::Gmtime(uint64_t stamp, const char *format, char *buf,
size_t Realtime::Localtime(const char *format, char *buf, size_t len) {
struct tm tmbuf;
time_t now = time(0);
time_t now = time(nullptr);
return strftime(buf, len, format, localtime_r(&now, &tmbuf));
}
size_t Realtime::Gmtime(const char *format, char *buf, size_t len) {
struct tm tmbuf;
time_t now = time(0);
time_t now = time(nullptr);
return strftime(buf, len, format, gmtime_r(&now, &tmbuf));
}
+2 -2
View File
@@ -70,9 +70,9 @@ uint64_t CgroupUtil::getUptime() {
struct timeval boottime;
size_t len = sizeof(boottime);
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(mib, 2, &boottime, &len, NULL, 0) == 0) {
if (sysctl(mib, 2, &boottime, &len, nullptr, 0) == 0) {
time_t bsec = boottime.tv_sec;
time_t csec = time(NULL);
time_t csec = time(nullptr);
return csec - bsec;
}
#elif defined(PLATFORM_WINDOWS)
@@ -152,7 +152,7 @@ ControlOp SearchCondCheckWalker::access(const QueryNode::Ptr &query_node,
return ControlOp::BREAK;
}
// more than one vector query check.
if (vector_rel_ != NULL) {
if (vector_rel_ != nullptr) {
err_msg_ = ailego::StringHelper::Concat(
"more than one vector search is not supported. ", vector_rel_->text(),
" ", query_rel_node->text());
+2 -2
View File
@@ -20,9 +20,9 @@ SQLInfo::Ptr QueryParser::parse(const std::string &query) {
ZVecSQLParser se_sql_parser_;
SQLInfo::Ptr sql_info = se_sql_parser_.parse(query);
if (sql_info == NULL) {
if (sql_info == nullptr) {
err_msg_ = se_sql_parser_.err_msg();
return NULL;
return nullptr;
}
return sql_info;
+1 -1
View File
@@ -49,7 +49,7 @@ const std::string &ZVecParser::formatted_tree() {
}
std::string ZVecParser::to_formatted_string_tree(void *tree, void *parser) {
if (tree == NULL || parser == NULL) {
if (tree == nullptr || parser == nullptr) {
return "";
}
@@ -28,6 +28,8 @@
extern "C" {
#endif
// NOLINTBEGIN
#define MOD_JSON_FALSE (false)
#define MOD_JSON_TRUE (true)
#define MOD_JSON_INFINITY (INFINITY)
@@ -567,7 +569,7 @@ int mod_json_string_assign(mod_json_string_t *str, mod_json_cchar_t *cstr,
static inline mod_json_string_t *mod_json_string_clone(mod_json_string_t *str) {
return (str ? mod_json_string_set(str->first,
(mod_json_size_t)(str->last - str->first))
: (mod_json_string_t *)0);
: (mod_json_string_t *)NULL);
}
/**
@@ -718,7 +720,7 @@ static inline mod_json_string_t *mod_json_string_grab(mod_json_string_t *str) {
* \return The pointer of c-string
*/
static inline mod_json_cchar_t *mod_json_string_cstr(mod_json_string_t *str) {
return (str ? str->first : (mod_json_cchar_t *)0);
return (str ? str->first : (mod_json_cchar_t *)NULL);
}
/**
@@ -727,7 +729,7 @@ static inline mod_json_cchar_t *mod_json_string_cstr(mod_json_string_t *str) {
* \return The pointer of data
*/
static inline mod_json_char_t *mod_json_string_data(mod_json_string_t *str) {
return (str ? str->first : (mod_json_char_t *)0);
return (str ? str->first : (mod_json_char_t *)NULL);
}
/**
@@ -1380,3 +1382,5 @@ mod_json_string_t *mod_json_dump(mod_json_value_t *val);
#if defined(__cplusplus)
} /* extern "C" */
#endif
// NOLINTEND
@@ -33,10 +33,10 @@ class JsonString {
typedef mod_json_integer_t integer_type;
//! Constructor
JsonString(void) : str_(0) {}
JsonString(void) : str_(nullptr) {}
//! Constructor
JsonString(const JsonString &rhs) : str_(0) {
JsonString(const JsonString &rhs) : str_(nullptr) {
if (rhs.str_) {
str_ = mod_json_string_grab(rhs.str_);
}
@@ -45,14 +45,14 @@ class JsonString {
#if __cplusplus >= 201103L
//! Constructor
JsonString(JsonString &&rhs) : str_(rhs.str_) {
rhs.str_ = 0;
rhs.str_ = nullptr;
}
#endif
//! Constructor
JsonString(const char *cstr) {
str_ = cstr ? mod_json_string_set(cstr, (mod_json_size_t)std::strlen(cstr))
: 0;
: nullptr;
}
//! Constructor
@@ -139,7 +139,7 @@ class JsonString {
//! Retrieve non-zero if the string is valid
bool is_valid(void) const {
return (str_ != (mod_json_string_t *)0);
return (str_ != (mod_json_string_t *)nullptr);
}
//! Retrieve non-zero if the string is empty
@@ -150,7 +150,7 @@ class JsonString {
//! Assign a JSON string
void assign(const JsonString &rhs) {
mod_json_string_unset(str_);
str_ = rhs.str_ ? mod_json_string_grab(rhs.str_) : 0;
str_ = rhs.str_ ? mod_json_string_grab(rhs.str_) : nullptr;
}
#if __cplusplus >= 201103L
@@ -158,7 +158,7 @@ class JsonString {
void assign(JsonString &&rhs) {
mod_json_string_unset(str_);
str_ = rhs.str_;
rhs.str_ = 0;
rhs.str_ = nullptr;
}
#endif
@@ -261,7 +261,7 @@ class JsonString {
//! Clear the JSON string
void clear(void) {
mod_json_string_unset(str_);
str_ = 0;
str_ = nullptr;
}
//! Exchange the content with another JSON string
@@ -375,7 +375,7 @@ class JsonString {
} else {
str_ = mod_json_string_set("", 0);
}
return (str_ != 0);
return (str_ != nullptr);
}
//! Clone the value and leak it
@@ -404,7 +404,7 @@ class JsonValue {
typedef mod_json_integer_t integer_type;
//! Constructor
JsonValue(void) : val_(0) {}
JsonValue(void) : val_(nullptr) {}
//! Constructor
explicit JsonValue(const bool &val) {
@@ -513,7 +513,7 @@ class JsonValue {
}
//! Constructor
JsonValue(const JsonValue &rhs) : val_(0) {
JsonValue(const JsonValue &rhs) : val_(nullptr) {
if (rhs.val_) {
val_ = mod_json_value_grab(rhs.val_);
}
@@ -522,7 +522,7 @@ class JsonValue {
#if __cplusplus >= 201103L
//! Constructor
JsonValue(JsonValue &&rhs) : val_(rhs.val_) {
rhs.val_ = 0;
rhs.val_ = nullptr;
}
#endif
@@ -717,7 +717,7 @@ class JsonValue {
//! Retrieve non-zero if the value is valid
bool is_valid(void) const {
return (val_ != (mod_json_value_t *)0);
return (val_ != (mod_json_value_t *)nullptr);
}
//! Retrieve non-zero if the value is a object
@@ -758,7 +758,7 @@ class JsonValue {
//! Assign new contents to the value, replacing its current content
void assign(const JsonValue &rhs) {
mod_json_value_unset(val_);
val_ = rhs.val_ ? mod_json_value_grab(rhs.val_) : 0;
val_ = rhs.val_ ? mod_json_value_grab(rhs.val_) : nullptr;
}
#if __cplusplus >= 201103L
@@ -766,7 +766,7 @@ class JsonValue {
void assign(JsonValue &&rhs) {
mod_json_value_unset(val_);
val_ = rhs.val_;
rhs.val_ = 0;
rhs.val_ = nullptr;
}
#endif
@@ -1048,7 +1048,7 @@ class JsonValue {
//! Parse a sting as a JSON value
bool parse(const char *str) {
mod_json_token_t *tok = mod_json_token_create(NULL);
mod_json_token_t *tok = mod_json_token_create(nullptr);
if (tok) {
mod_json_value_t *jval = mod_json_parse(tok, str);
@@ -1084,7 +1084,7 @@ class JsonValue {
} else {
val_ = mod_json_value_set_null();
}
return (val_ != 0);
return (val_ != nullptr);
}
//! Clone the value and leak it
@@ -1153,7 +1153,7 @@ class JsonArray {
class const_iterator {
public:
//! Constructor
const_iterator(void) : iter_(0) {}
const_iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const const_iterator &rhs) const {
@@ -1224,7 +1224,7 @@ class JsonArray {
class iterator {
public:
//! Constructor
iterator(void) : iter_(0) {}
iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const iterator &rhs) const {
@@ -1303,7 +1303,7 @@ class JsonArray {
class const_reverse_iterator {
public:
//! Constructor
const_reverse_iterator(void) : iter_(0) {}
const_reverse_iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const const_reverse_iterator &rhs) const {
@@ -1374,7 +1374,7 @@ class JsonArray {
class reverse_iterator {
public:
//! Constructor
reverse_iterator(void) : iter_(0) {}
reverse_iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const reverse_iterator &rhs) const {
@@ -1449,10 +1449,10 @@ class JsonArray {
};
//! Constructor
JsonArray(void) : arr_(0) {}
JsonArray(void) : arr_(nullptr) {}
//! Constructor
JsonArray(const JsonArray &rhs) : arr_(0) {
JsonArray(const JsonArray &rhs) : arr_(nullptr) {
if (rhs.arr_) {
arr_ = mod_json_array_grab(rhs.arr_);
}
@@ -1461,7 +1461,7 @@ class JsonArray {
#if __cplusplus >= 201103L
//! Constructor
JsonArray(JsonArray &&rhs) : arr_(rhs.arr_) {
rhs.arr_ = 0;
rhs.arr_ = nullptr;
}
#endif
@@ -1506,7 +1506,7 @@ class JsonArray {
//! Retrieve non-zero if the array is valid
bool is_valid(void) const {
return (arr_ != (mod_json_array_t *)0);
return (arr_ != (mod_json_array_t *)nullptr);
}
//! Retrieve non-zero if the array is empty
@@ -1532,7 +1532,7 @@ class JsonArray {
//! Assign new contents to the array, replacing its current content
void assign(const JsonArray &rhs) {
mod_json_array_unset(arr_);
arr_ = rhs.arr_ ? mod_json_array_grab(rhs.arr_) : 0;
arr_ = rhs.arr_ ? mod_json_array_grab(rhs.arr_) : nullptr;
}
#if __cplusplus >= 201103L
@@ -1540,7 +1540,7 @@ class JsonArray {
void assign(JsonArray &&rhs) {
mod_json_array_unset(arr_);
arr_ = rhs.arr_;
rhs.arr_ = 0;
rhs.arr_ = nullptr;
}
#endif
@@ -1648,7 +1648,7 @@ class JsonArray {
//! Clear the JSON array
void clear(void) {
mod_json_array_unset(arr_);
arr_ = 0;
arr_ = nullptr;
}
//! Exchange the content with another JSON array
@@ -1781,7 +1781,7 @@ class JsonArray {
} else {
arr_ = mod_json_array_set_default();
}
return (arr_ != 0);
return (arr_ != nullptr);
}
//! Clone the array and leak it
@@ -1812,11 +1812,11 @@ class JsonArray {
class JsonPair {
public:
//! Constructor
JsonPair(void) : pair_(0) {}
JsonPair(void) : pair_(nullptr) {}
//! Retrieve non-zero if the pair is valid
bool is_valid(void) const {
return (pair_ != (mod_json_pair_t *)0);
return (pair_ != (mod_json_pair_t *)nullptr);
}
//! Retrieve the key of pair
@@ -1864,7 +1864,7 @@ class JsonObject {
class const_iterator {
public:
//! Constructor
const_iterator(void) : iter_(0) {}
const_iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const const_iterator &rhs) const {
@@ -1935,7 +1935,7 @@ class JsonObject {
class iterator {
public:
//! Constructor
iterator(void) : iter_(0) {}
iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const iterator &rhs) const {
@@ -2014,7 +2014,7 @@ class JsonObject {
class const_reverse_iterator {
public:
//! Constructor
const_reverse_iterator(void) : iter_(0) {}
const_reverse_iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const const_reverse_iterator &rhs) const {
@@ -2085,7 +2085,7 @@ class JsonObject {
class reverse_iterator {
public:
//! Constructor
reverse_iterator(void) : iter_(0) {}
reverse_iterator(void) : iter_(nullptr) {}
//! Equality
bool operator==(const reverse_iterator &rhs) const {
@@ -2160,10 +2160,10 @@ class JsonObject {
};
//! Constructor
JsonObject(void) : obj_(0) {}
JsonObject(void) : obj_(nullptr) {}
//! Constructor
JsonObject(const JsonObject &rhs) : obj_(0) {
JsonObject(const JsonObject &rhs) : obj_(nullptr) {
if (rhs.obj_) {
obj_ = mod_json_object_grab(rhs.obj_);
}
@@ -2172,7 +2172,7 @@ class JsonObject {
#if __cplusplus >= 201103L
//! Constructor
JsonObject(JsonObject &&rhs) : obj_(rhs.obj_) {
rhs.obj_ = 0;
rhs.obj_ = nullptr;
}
#endif
@@ -2244,7 +2244,7 @@ class JsonObject {
//! Retrieve non-zero if the object is valid
bool is_valid(void) const {
return (obj_ != (mod_json_object_t *)0);
return (obj_ != (mod_json_object_t *)nullptr);
}
//! Retrieve non-zero if the object is empty
@@ -2265,7 +2265,7 @@ class JsonObject {
//! Assign new contents to the object, replacing its current content
void assign(const JsonObject &rhs) {
mod_json_object_unset(obj_);
obj_ = rhs.obj_ ? mod_json_object_grab(rhs.obj_) : 0;
obj_ = rhs.obj_ ? mod_json_object_grab(rhs.obj_) : nullptr;
}
#if __cplusplus >= 201103L
@@ -2273,14 +2273,14 @@ class JsonObject {
void assign(JsonObject &&rhs) {
mod_json_object_unset(obj_);
obj_ = rhs.obj_;
rhs.obj_ = 0;
rhs.obj_ = nullptr;
}
#endif
//! Clear the JSON object
void clear(void) {
mod_json_object_unset(obj_);
obj_ = 0;
obj_ = nullptr;
}
//! Set the value of a key
@@ -2291,7 +2291,7 @@ class JsonObject {
}
return (mod_json_object_insert(obj_, *(mod_json_string_t **)&key,
*(mod_json_value_t **)&tmp) !=
(mod_json_pair_t *)0);
(mod_json_pair_t *)nullptr);
}
//! Retrieve the value of a key
@@ -2518,7 +2518,7 @@ class JsonObject {
//! Retrieve non-zero if the key exists in JSON object
bool has(const char *key) const {
return (mod_json_object_find(obj_, key) != (mod_json_pair_t *)0);
return (mod_json_object_find(obj_, key) != (mod_json_pair_t *)nullptr);
}
//! Exchange the content with another JSON object
@@ -2643,7 +2643,7 @@ class JsonObject {
} else {
obj_ = mod_json_object_set_default();
}
return (obj_ != 0);
return (obj_ != nullptr);
}
//! Clone the object and leak it
@@ -2755,7 +2755,9 @@ class JsonParser {
//! Constructor
JsonParser(void)
: state_(mod_json_state_null), error_(mod_json_error_null), context_(0) {
: state_(mod_json_state_null),
error_(mod_json_error_null),
context_(nullptr) {
option_.options = 0;
option_.object_depth = 0;
option_.array_depth = 0;
+24 -24
View File
@@ -92,7 +92,7 @@ TEST(FixedBitset, General) {
}
TEST(FixedBitset, And) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<3552> bitset1;
@@ -137,7 +137,7 @@ TEST(FixedBitset, And) {
}
TEST(FixedBitset, Andnot) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -183,7 +183,7 @@ TEST(FixedBitset, Andnot) {
}
TEST(FixedBitset, Or) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -228,7 +228,7 @@ TEST(FixedBitset, Or) {
}
TEST(FixedBitset, Xor) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -362,7 +362,7 @@ TEST(FixedBitset, TestNone) {
}
TEST(FixedBitset, Extract) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -386,7 +386,7 @@ TEST(FixedBitset, Extract) {
}
TEST(FixedBitset, BitwiseXorCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -425,7 +425,7 @@ TEST(FixedBitset, BitwiseXorCardinality) {
}
TEST(FixedBitset, BitwiseOrCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -458,7 +458,7 @@ TEST(FixedBitset, BitwiseOrCardinality) {
}
TEST(FixedBitset, BitwiseAndCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -491,7 +491,7 @@ TEST(FixedBitset, BitwiseAndCardinality) {
}
TEST(FixedBitset, BitwiseAndnotCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<2528> bitset1;
@@ -527,7 +527,7 @@ TEST(FixedBitset, BitwiseAndnotCardinality) {
}
TEST(FixedBitset, Benchmark) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
const uint32_t dimension = 2048u;
@@ -716,7 +716,7 @@ TEST(Bitset, General) {
}
TEST(Bitset, BitwiseXorCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitset bitset1;
@@ -758,7 +758,7 @@ TEST(Bitset, BitwiseXorCardinality) {
}
TEST(Bitset, BitwiseOrCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitset bitset1;
@@ -796,7 +796,7 @@ TEST(Bitset, BitwiseOrCardinality) {
}
TEST(Bitset, BitwiseAndCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitset bitset1;
@@ -834,7 +834,7 @@ TEST(Bitset, BitwiseAndCardinality) {
}
TEST(Bitset, BitwiseAndnotCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitset bitset1;
@@ -979,7 +979,7 @@ TEST(Bitmap, ShrinkToFit) {
}
TEST(Bitmap, And) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1, bitmap2;
@@ -1010,7 +1010,7 @@ TEST(Bitmap, And) {
}
TEST(Bitmap, Andnot) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1, bitmap2;
@@ -1041,7 +1041,7 @@ TEST(Bitmap, Andnot) {
}
TEST(Bitmap, Or) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1, bitmap2;
@@ -1072,7 +1072,7 @@ TEST(Bitmap, Or) {
}
TEST(Bitmap, Xor) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1, bitmap2;
@@ -1232,7 +1232,7 @@ TEST(Bitmap, TestNone) {
}
TEST(Bitmap, Extract) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1;
@@ -1256,7 +1256,7 @@ TEST(Bitmap, Extract) {
}
TEST(Bitmap, BitwiseXorCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1;
@@ -1295,7 +1295,7 @@ TEST(Bitmap, BitwiseXorCardinality) {
}
TEST(Bitmap, BitwiseOrCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1;
@@ -1330,7 +1330,7 @@ TEST(Bitmap, BitwiseOrCardinality) {
}
TEST(Bitmap, BitwiseAndCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1;
@@ -1365,7 +1365,7 @@ TEST(Bitmap, BitwiseAndCardinality) {
}
TEST(Bitmap, BitwiseAndnotCardinality) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1;
@@ -1401,7 +1401,7 @@ TEST(Bitmap, BitwiseAndnotCardinality) {
}
TEST(Bitmap, Benchmark) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
Bitmap bitmap1, bitmap2;
+6 -6
View File
@@ -367,7 +367,7 @@ TEST(Json, JsonParser) {
parser.set_simple(true);
EXPECT_TRUE(parser.parse(str.c_str(), &val));
EXPECT_TRUE(val["abcd"].as_c_string() == NULL);
EXPECT_TRUE(val["abcd"].as_c_string() == nullptr);
EXPECT_TRUE(val["abcd/*//*/"].as_c_string() == std::string("1234"));
parser.set_comment(true);
@@ -401,7 +401,7 @@ TEST(Json, JsonParser) {
parser.set_comment(true);
EXPECT_TRUE(parser.parse(str.c_str(), &val));
EXPECT_TRUE(val["abcd"].as_c_string() == NULL);
EXPECT_TRUE(val["abcd"].as_c_string() == nullptr);
EXPECT_TRUE(val["abcd\""].as_c_string() == std::string("1234"));
}
@@ -424,7 +424,7 @@ TEST(Json, JsonParser) {
std::string str = "{ , \n: \t \"1234\" }";
EXPECT_FALSE(parser.parse(str.c_str(), &val));
EXPECT_TRUE(val[""].as_c_string() == NULL);
EXPECT_TRUE(val[""].as_c_string() == nullptr);
parser.set_simple(true);
EXPECT_FALSE(parser.parse(str.c_str(), &val));
@@ -1102,7 +1102,7 @@ TEST(Json, JsonArray) {
EXPECT_TRUE(arr.capacity() == 0);
arr.resize(0);
EXPECT_TRUE(arr.capacity() == 32);
arr.push(0);
arr.push(nullptr);
EXPECT_TRUE(arr.capacity() == 32);
EXPECT_TRUE(arr.size() == 1);
arr.resize(0);
@@ -1396,7 +1396,7 @@ TEST(Json, JsonString) {
{
JsonString a;
JsonString b("\0");
JsonString c(NULL);
JsonString c(nullptr);
EXPECT_TRUE(a == c);
EXPECT_TRUE(b == c);
EXPECT_TRUE(b == a);
@@ -1405,7 +1405,7 @@ TEST(Json, JsonString) {
{
JsonString a;
JsonString b("\0", 1);
JsonString c(NULL);
JsonString c(nullptr);
EXPECT_TRUE(a == c);
EXPECT_TRUE(b != c);
EXPECT_TRUE(b != a);
+2 -2
View File
@@ -78,7 +78,7 @@ TEST(Crc32c, Crc32c) {
}
TEST(Crc32c, Crc32cChecksum) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
{
@@ -118,7 +118,7 @@ TEST(Crc32c, Crc32cChecksum) {
}
TEST(Crc32c, Crc32cBenchmark) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
size_t len = 100000;
@@ -50,7 +50,7 @@ static inline void MatrixTranspose(uint64_t *dst, const uint64_t *src, size_t M,
}
TEST(DistanceMatrix, Hamming_General) {
srand((uint32_t)time(NULL));
srand((uint32_t)time(nullptr));
srand((uint32_t)rand());
FixedBitset<63936> bitset1;
+1 -1
View File
@@ -66,7 +66,7 @@ Doc CreateDoc(const uint64_t doc_id) {
void InsertDoc(const MemForwardStore::Ptr &store, const uint64_t start_doc_id,
const uint64_t end_doc_id) {
srand(time(NULL));
srand(time(nullptr));
for (auto doc_id = start_doc_id; doc_id < end_doc_id; doc_id++) {
if (store) {
Doc new_doc = CreateDoc(doc_id);
+1 -1
View File
@@ -153,7 +153,7 @@ inline Doc CreateDoc(const uint64_t doc_id) {
inline Status InsertDoc(const Segment::Ptr &segment,
const uint64_t start_doc_id,
const uint64_t end_doc_id) {
srand(time(NULL));
srand(time(nullptr));
long long create_total = 0;
long long insert_total = 0;
for (auto doc_id = start_doc_id; doc_id < end_doc_id; doc_id++) {
+1 -1
View File
@@ -37,7 +37,7 @@ using CreateDocFun = Doc (*)(const uint64_t doc_id);
inline Status InsertDoc(const Segment::Ptr &segment,
const uint64_t start_doc_id, const uint64_t end_doc_id,
CreateDocFun create_doc) {
srand(time(NULL));
srand(time(nullptr));
long long create_total = 0;
long long insert_total = 0;
for (auto doc_id = start_doc_id; doc_id < end_doc_id; doc_id++) {