Skip to content

[bugfix]: 修改在数据库未初始化时调用API接口日志打印可能出现的空指针字符串打印操作问题 #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/fdb_kvdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include <fdb_low_lvl.h>

#define FDB_LOG_TAG "[kv]"
/* rewrite log prefix */
#undef FDB_LOG_PREFIX2
#define FDB_LOG_PREFIX2() FDB_PRINT("[%s][%s] ", db_name(db), _fdb_db_path((fdb_db_t)db))

#if defined(FDB_USING_KVDB)

Expand Down Expand Up @@ -434,7 +431,7 @@ static fdb_err_t read_sector_info(fdb_kvdb_t db, uint32_t addr, kv_sec_info_t se
sector->addr = addr;
sector->magic = sec_hdr.magic;
/* check magic word and combined value */
if (sector->magic != SECTOR_MAGIC_WORD ||
if (sector->magic != SECTOR_MAGIC_WORD ||
(sec_hdr.combined != SECTOR_NOT_COMBINED && sec_hdr.combined != SECTOR_COMBINED)) {
sector->check_ok = false;
sector->combined = SECTOR_NOT_COMBINED;
Expand Down Expand Up @@ -653,8 +650,8 @@ fdb_kv_t fdb_kv_get_obj(fdb_kvdb_t db, const char *key, fdb_kv_t kv)
{
bool find_ok = false;

if (!db_init_ok(db)) {
FDB_INFO("Error: KV (%s) isn't initialize OK.\n", db_name(db));
if (!db_init_ok(db)) {
FDB_INFO("Error: KV isn't initialize OK.\n");
return 0;
}

Expand Down Expand Up @@ -700,7 +697,7 @@ size_t fdb_kv_get_blob(fdb_kvdb_t db, const char *key, fdb_blob_t blob)
size_t read_len = 0;

if (!db_init_ok(db)) {
FDB_INFO("Error: KV (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: KV isn't initialize OK.\n");
return 0;
}

Expand Down Expand Up @@ -1300,7 +1297,7 @@ fdb_err_t fdb_kv_del(fdb_kvdb_t db, const char *key)
fdb_err_t result = FDB_NO_ERR;

if (!db_init_ok(db)) {
FDB_INFO("Error: KV (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: KV isn't initialize OK.\n");
return FDB_INIT_FAILED;
}

Expand Down Expand Up @@ -1364,7 +1361,7 @@ fdb_err_t fdb_kv_set_blob(fdb_kvdb_t db, const char *key, fdb_blob_t blob)
fdb_err_t result = FDB_NO_ERR;

if (!db_init_ok(db)) {
FDB_INFO("Error: KV (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: KV isn't initialize OK.\n");
return FDB_INIT_FAILED;
}

Expand Down Expand Up @@ -1512,7 +1509,7 @@ void fdb_kv_print(fdb_kvdb_t db)
size_t using_size = 0;

if (!db_init_ok(db)) {
FDB_INFO("Error: KV (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: KV isn't initialize OK.\n");
return;
}

Expand Down Expand Up @@ -1816,9 +1813,9 @@ fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *path, struc

FDB_DEBUG("KVDB size is %" PRIu32 " bytes.\n", db_max_size(db));
db_unlock(db);

result = _fdb_kv_load(db);

db_lock(db);
#ifdef FDB_KV_AUTO_UPDATE
if (result == FDB_NO_ERR) {
Expand Down Expand Up @@ -1933,7 +1930,7 @@ fdb_err_t fdb_kvdb_check(fdb_kvdb_t db)
struct fdb_kv kv;

if (!db_init_ok(db)) {
FDB_INFO("Error: KV (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: KV isn't initialize OK.\n");
return FDB_INIT_FAILED;
}

Expand Down
17 changes: 7 additions & 10 deletions src/fdb_tsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#include <fdb_low_lvl.h>

#define FDB_LOG_TAG "[tsl]"
/* rewrite log prefix */
#undef FDB_LOG_PREFIX2
#define FDB_LOG_PREFIX2() FDB_PRINT("[%s][%s] ", db_name(db), _fdb_db_path((fdb_db_t)db))

#if defined(FDB_USING_TSDB)

Expand Down Expand Up @@ -391,7 +388,7 @@ static fdb_err_t tsl_append(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t *timestam
/* check the append length, MUST less than the db->max_len */
if(blob->size > db->max_len)
{
FDB_INFO("Warning: append length (%" PRIdMAX ") is more than the db->max_len (%" PRIdMAX "). This tsl will be dropped.\n",
FDB_INFO("Warning: append length (%" PRIdMAX ") is more than the db->max_len (%" PRIdMAX "). This tsl will be dropped.\n",
(intmax_t)blob->size, (intmax_t)(db->max_len));
return FDB_WRITE_ERR;
}
Expand Down Expand Up @@ -439,7 +436,7 @@ fdb_err_t fdb_tsl_append(fdb_tsdb_t db, fdb_blob_t blob)
fdb_err_t result = FDB_NO_ERR;

if (!db_init_ok(db)) {
FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: TSL isn't initialize OK.\n");
return FDB_INIT_FAILED;
}

Expand All @@ -463,7 +460,7 @@ fdb_err_t fdb_tsl_append_with_ts(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t time
fdb_err_t result = FDB_NO_ERR;

if (!db_init_ok(db)) {
FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: TSL isn't initialize OK.\n");
return FDB_INIT_FAILED;
}

Expand All @@ -488,7 +485,7 @@ void fdb_tsl_iter(fdb_tsdb_t db, fdb_tsl_cb cb, void *arg)
struct fdb_tsl tsl;

if (!db_init_ok(db)) {
FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: TSL isn't initialize OK.\n");
}

if (cb == NULL) {
Expand Down Expand Up @@ -538,7 +535,7 @@ void fdb_tsl_iter_reverse(fdb_tsdb_t db, fdb_tsl_cb cb, void *cb_arg)
struct fdb_tsl tsl;

if (!db_init_ok(db)) {
FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: TSL isn't initialize OK.\n");
}

if (cb == NULL) {
Expand Down Expand Up @@ -627,7 +624,7 @@ void fdb_tsl_iter_by_time(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl
uint32_t (*get_tsl_addr)(tsdb_sec_info_t , fdb_tsl_t);

if (!db_init_ok(db)) {
FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: TSL isn't initialize OK.\n");
}

if(from <= to) {
Expand Down Expand Up @@ -722,7 +719,7 @@ size_t fdb_tsl_query_count(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_ts
arg.status = status;

if (!db_init_ok(db)) {
FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
FDB_INFO("Error: TSL isn't initialize OK.\n");
return 0;
}

Expand Down