From b6dfe61cae862ddf252520689536122fe7fd2b92 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Thu, 2 Nov 2023 22:29:41 +0800 Subject: [PATCH] analysis/meta: minor cleanup --- librz/analysis/analysis.c | 19 ++++++++----------- librz/analysis/meta.c | 5 +++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/librz/analysis/analysis.c b/librz/analysis/analysis.c index b474edfa83a..5d0d18e4ff9 100644 --- a/librz/analysis/analysis.c +++ b/librz/analysis/analysis.c @@ -44,16 +44,13 @@ void rz_analysis_hint_storage_init(RzAnalysis *a); void rz_analysis_hint_storage_fini(RzAnalysis *a); -static void rz_meta_item_fini(RzAnalysisMetaItem *item) { - free(item->str); -} - -static void rz_meta_item_free(void *_item) { - if (_item) { - RzAnalysisMetaItem *item = _item; - rz_meta_item_fini(item); - free(item); +static void meta_item_free(void *item) { + if (!item) { + return; } + RzAnalysisMetaItem *it = item; + free(it->str); + free(it); } static void global_kv_free(HtPPKv *kv) { @@ -88,7 +85,7 @@ RZ_API RzAnalysis *rz_analysis_new(void) { rz_event_hook(analysis->meta_spaces.event, RZ_SPACE_EVENT_COUNT, meta_count_for, NULL); rz_analysis_hint_storage_init(analysis); - rz_interval_tree_init(&analysis->meta, rz_meta_item_free); + rz_interval_tree_init(&analysis->meta, meta_item_free); analysis->typedb = rz_type_db_new(); analysis->sdb_fmts = sdb_ns(analysis->sdb, "spec", 1); analysis->sdb_cc = sdb_ns(analysis->sdb, "cc", 1); @@ -448,7 +445,7 @@ RZ_API bool rz_analysis_op_is_eob(RzAnalysisOp *op) { RZ_API void rz_analysis_purge(RzAnalysis *analysis) { rz_analysis_hint_clear(analysis); rz_interval_tree_fini(&analysis->meta); - rz_interval_tree_init(&analysis->meta, rz_meta_item_free); + rz_interval_tree_init(&analysis->meta, meta_item_free); rz_type_db_purge(analysis->typedb); sdb_reset(analysis->sdb_classes); sdb_reset(analysis->sdb_classes_attrs); diff --git a/librz/analysis/meta.c b/librz/analysis/meta.c index c3b2918d17c..b93a0aa4dc9 100644 --- a/librz/analysis/meta.c +++ b/librz/analysis/meta.c @@ -120,7 +120,7 @@ static bool meta_set(RzAnalysis *a, RzAnalysisMetaType type, int subtype, ut64 f item->size = to - from + 1; free(item->str); if (is_string_with_zeroes(type, subtype)) { - item->str = str ? rz_str_ndup(str, item->size) : NULL; + item->str = rz_str_ndup(str, item->size); } else { item->str = str ? strdup(str) : NULL; } @@ -138,7 +138,8 @@ static bool meta_set(RzAnalysis *a, RzAnalysisMetaType type, int subtype, ut64 f return true; } -RZ_API bool rz_meta_set_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, const char *s) { +RZ_API bool rz_meta_set_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, RZ_NULLABLE const char *s) { + rz_return_val_if_fail(a, false); // By default all strings are UTF-8 return meta_set(a, type, RZ_STRING_ENC_UTF8, addr, addr, s); }