Skip to content

Commit

Permalink
analysis/meta: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Nov 6, 2023
1 parent 5d3307a commit 75f6298
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
19 changes: 8 additions & 11 deletions librz/analysis/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions librz/analysis/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ RZ_API bool rz_meta_set_with_subtype(RzAnalysis *m, RzAnalysisMetaType type, int
RZ_API void rz_meta_del(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, ut64 size);

// Same as rz_meta_set() with a size of 1.
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);

// Convenience function to get the str content of the item at addr with given type in the current space.
RZ_API const char *rz_meta_get_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr);
Expand Down

0 comments on commit 75f6298

Please sign in to comment.