chore: please cppcheck
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/docker Pipeline was successful Details

release/0.2.0
Jef Roosens 2023-11-18 22:28:50 +01:00
parent 9c387937ef
commit a2d4b970e7
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 19 additions and 10 deletions

View File

@ -47,6 +47,8 @@ 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;
}
@ -55,6 +57,9 @@ 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;
}
@ -65,6 +70,8 @@ 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;
}
}
@ -73,7 +80,10 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) {
store->db.f = db_file;
store->idx.f = idx_file;
LSM_RES(lsm_store_load_db(store));
LSM_RES2(lsm_store_load_db(store), {
fclose(db_file);
fclose(idx_file);
});
*ptr = store;

View File

@ -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, void *val) {
uint64_t count, const 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, lsm_str *s) {
static lsm_error lsm_write_str(uint64_t *sum, FILE *f, const 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;
lsm_entry *entry = handle->wrapper->entry;
const lsm_entry *entry = handle->wrapper->entry;
pthread_mutex_lock(&store->idx.lock);

View File

@ -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 ? key->len : LSM_STORE_DATA_LEVELS;
key->len > LSM_STORE_DATA_LEVELS ? LSM_STORE_DATA_LEVELS : key->len;
memcpy(path, lsm_str_ptr(data_path), data_path->len);
path[data_path->len] = '/';
@ -255,6 +255,7 @@ 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] = '/';
@ -279,6 +280,7 @@ 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';

View File

@ -9,15 +9,12 @@
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 = strdup(default); \
} else { \
var = strdup(var); \
var = default; \
}
int main() {