diff --git a/Makefile b/Makefile index f2c448c..63c35f2 100644 --- a/Makefile +++ b/Makefile @@ -106,14 +106,10 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c .PHONY: lint lint: clang-format -n --Werror $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL) - make -C lsm lint - make -C landerctl lint .PHONY: fmt fmt: clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL) - make -C lsm fmt - make -C landerctl fmt .PHONY: check check: @@ -121,21 +117,21 @@ check: cppcheck \ $(addprefix -I,$(INC_DIRS)) \ --cppcheck-build-dir=$(BUILD_DIR)/cppcheck \ + --project=compile_commands.json \ --error-exitcode=1 \ --enable=warning,style \ + -ithirdparty/* \ + -itrie/* \ --inline-suppr \ --check-level=exhaustive \ --quiet \ - -j$(shell nproc) \ - $(SRCS) - make -C lsm check - make -C landerctl check + -j$(shell nproc) .PHONY: clean clean: rm -rf $(BUILD_DIR) $(MAKE) -C lsm clean - $(MAKE) -C landerctl clean + .PHONY: bear bear: clean diff --git a/landerctl/Makefile b/landerctl/Makefile index 487e0f2..72b8239 100644 --- a/landerctl/Makefile +++ b/landerctl/Makefile @@ -98,13 +98,13 @@ check: cppcheck \ $(addprefix -I,$(INC_DIRS)) \ --cppcheck-build-dir=$(BUILD_DIR)/cppcheck \ + --project=compile_commands.json \ --error-exitcode=1 \ --enable=warning,style \ --inline-suppr \ --check-level=exhaustive \ --quiet \ - -j$(shell nproc) \ - $(SRCS) + -j$(shell nproc) .PHONY: clean clean: diff --git a/lsm/Makefile b/lsm/Makefile index 716d82d..c853ed9 100644 --- a/lsm/Makefile +++ b/lsm/Makefile @@ -97,20 +97,6 @@ lint: fmt: clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL) $(SRCS_EXAMPLE) -.PHONY: check -check: - mkdir -p $(BUILD_DIR)/cppcheck - cppcheck \ - $(addprefix -I,$(INC_DIRS)) \ - --cppcheck-build-dir=$(BUILD_DIR)/cppcheck \ - --error-exitcode=1 \ - --enable=warning,style \ - --inline-suppr \ - --check-level=exhaustive \ - --quiet \ - -j$(shell nproc) \ - $(SRCS) - .PHONY: clean clean: rm -rf $(BUILD_DIR) diff --git a/lsm/src/store/lsm_store_disk_read.c b/lsm/src/store/lsm_store_disk_read.c index 721b4f3..b3e057a 100644 --- a/lsm/src/store/lsm_store_disk_read.c +++ b/lsm/src/store/lsm_store_disk_read.c @@ -47,8 +47,6 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) { idx_file = fopen(idx_file_path, "wb"); if (idx_file == NULL) { - fclose(db_file); - return lsm_error_failed_io; } @@ -57,9 +55,6 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) { uint64_t num = 0; if (fwrite(&num, sizeof(uint64_t), 1, idx_file) == 0) { - fclose(db_file); - fclose(idx_file); - return lsm_error_failed_io; } @@ -70,8 +65,6 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) { idx_file = fopen(idx_file_path, "r+b"); if (idx_file == NULL) { - fclose(db_file); - return lsm_error_failed_io; } } @@ -80,10 +73,7 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) { store->db.f = db_file; store->idx.f = idx_file; - LSM_RES2(lsm_store_load_db(store), { - fclose(db_file); - fclose(idx_file); - }); + LSM_RES(lsm_store_load_db(store)); *ptr = store; diff --git a/lsm/src/store/lsm_store_disk_write.c b/lsm/src/store/lsm_store_disk_write.c index 31f907b..b6906e6 100644 --- a/lsm/src/store/lsm_store_disk_write.c +++ b/lsm/src/store/lsm_store_disk_write.c @@ -1,7 +1,7 @@ #include "lsm/store_internal.h" static lsm_error lsm_fwrite(uint64_t *sum, FILE *f, uint64_t size, - uint64_t count, const void *val) { + uint64_t count, void *val) { size_t res = fwrite(val, size, count, f); if (res < count) { @@ -15,7 +15,7 @@ static lsm_error lsm_fwrite(uint64_t *sum, FILE *f, uint64_t size, return lsm_error_ok; } -static lsm_error lsm_write_str(uint64_t *sum, FILE *f, const lsm_str *s) { +static lsm_error lsm_write_str(uint64_t *sum, FILE *f, lsm_str *s) { uint64_t len = lsm_str_len(s); LSM_RES(lsm_fwrite(sum, f, sizeof(uint64_t), 1, &len)); @@ -129,7 +129,7 @@ lsm_error lsm_entry_disk_insert(lsm_entry_handle *handle) { // its entry to zero lsm_error lsm_entry_disk_remove(lsm_entry_handle *handle) { lsm_store *store = handle->store; - const lsm_entry *entry = handle->wrapper->entry; + lsm_entry *entry = handle->wrapper->entry; pthread_mutex_lock(&store->idx.lock); diff --git a/lsm/src/store/lsm_store_entry.c b/lsm/src/store/lsm_store_entry.c index 63d90a7..89e3ea7 100644 --- a/lsm/src/store/lsm_store_entry.c +++ b/lsm/src/store/lsm_store_entry.c @@ -247,7 +247,7 @@ void lsm_entry_data_path(char *path, const lsm_entry_handle *handle) { const lsm_str *key = handle->wrapper->entry->key; uint8_t levels = - key->len > LSM_STORE_DATA_LEVELS ? LSM_STORE_DATA_LEVELS : key->len; + key->len <= LSM_STORE_DATA_LEVELS ? key->len : LSM_STORE_DATA_LEVELS; memcpy(path, lsm_str_ptr(data_path), data_path->len); path[data_path->len] = '/'; @@ -255,7 +255,6 @@ void lsm_entry_data_path(char *path, const lsm_entry_handle *handle) { uint64_t index = data_path->len + 1; // Create each directory in the file hierarchy - // cppcheck-suppress knownConditionTrueFalse for (uint8_t i = 0; i < levels; i++) { path[index] = lsm_str_char(key, i); path[index + 1] = '/'; @@ -280,7 +279,6 @@ lsm_error lsm_entry_data_open_write(lsm_entry_handle *handle) { key->len <= LSM_STORE_DATA_LEVELS ? key->len : LSM_STORE_DATA_LEVELS; // Create all required directories in the path - // cppcheck-suppress knownConditionTrueFalse for (uint8_t i = 0; i < levels; i++) { path[data_path->len + 2 * (i + 1)] = '\0'; diff --git a/src/main.c b/src/main.c index 2f52fc1..fa9c64f 100644 --- a/src/main.c +++ b/src/main.c @@ -9,12 +9,15 @@ const char *var = getenv(env_var); \ if (var == NULL) { \ critical(1, "Missing environment variable %s", env_var); \ - } + } \ + var = strdup(var); #define ENV_OPT(var, env_var, default) \ const char *var = getenv(env_var); \ if (var == NULL) { \ - var = default; \ + var = strdup(default); \ + } else { \ + var = strdup(var); \ } int main() {