diff --git a/librz/arch/isa/hexagon/hexagon_arch.c b/librz/arch/isa/hexagon/hexagon_arch.c index 9eaf792065d..a52436ee7ff 100644 --- a/librz/arch/isa/hexagon/hexagon_arch.c +++ b/librz/arch/isa/hexagon/hexagon_arch.c @@ -1206,15 +1206,15 @@ RZ_API bool hexagon_decode_iword(RZ_OUT RzAnalysisInsnWord *iword, ut64 addr, co set_iword_properties(aop->type, iword); if (iword->props & RZ_ANALYSIS_IWORD_CALL && aop->jump != UT64_MAX) { - set_u_add(iword->call_targets, aop->jump); + rz_set_u_add(iword->call_targets, aop->jump); } else if (aop->jump != UT64_MAX) { - set_u_add(iword->jump_targets, aop->jump); + rz_set_u_add(iword->jump_targets, aop->jump); } if (hic->pkt_info.last_insn) { if (aop->type != RZ_ANALYSIS_OP_TYPE_RET && !rz_analysis_op_is_jump(aop)) { ut64 next_iword_addr = addr + iword->size_bytes; - set_u_add(iword->jump_targets, next_iword_addr); + rz_set_u_add(iword->jump_targets, next_iword_addr); } return true; } diff --git a/librz/arch/op.c b/librz/arch/op.c index 86b79df116f..ca11a9b4112 100644 --- a/librz/arch/op.c +++ b/librz/arch/op.c @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2010-2020 nibble // SPDX-License-Identifier: LGPL-3.0-only -#include +#include #include #include #include @@ -700,8 +700,8 @@ RZ_API RZ_OWN RzAnalysisInsnWord *rz_analysis_insn_word_new() { } iword->asm_str = rz_strbuf_new(""); iword->insns = rz_pvector_new(rz_analysis_op_free); - iword->jump_targets = set_u_new(); - iword->call_targets = set_u_new(); + iword->jump_targets = rz_set_u_new(); + iword->call_targets = rz_set_u_new(); if (!iword->asm_str || !iword->insns || !iword->jump_targets) { rz_analysis_insn_word_free(iword); return NULL; @@ -722,8 +722,8 @@ RZ_API void rz_analysis_insn_word_setup(RZ_BORROW RZ_NONNULL RzAnalysisInsnWord rz_analysis_insn_word_fini(iword); iword->asm_str = rz_strbuf_new(""); iword->insns = rz_pvector_new(rz_analysis_op_free); - iword->jump_targets = set_u_new(); - iword->call_targets = set_u_new(); + iword->jump_targets = rz_set_u_new(); + iword->call_targets = rz_set_u_new(); if (!iword->asm_str || !iword->insns || !iword->jump_targets) { rz_analysis_insn_word_fini(iword); } @@ -735,8 +735,8 @@ RZ_API void rz_analysis_insn_word_fini(RZ_OWN RZ_NULLABLE RzAnalysisInsnWord *iw } rz_strbuf_free(iword->asm_str); rz_pvector_free(iword->insns); - set_u_free(iword->jump_targets); - set_u_free(iword->call_targets); + rz_set_u_free(iword->jump_targets); + rz_set_u_free(iword->call_targets); rz_il_op_effect_free(iword->il_op); rz_mem_memzero(iword, sizeof(RzAnalysisInsnWord)); } diff --git a/librz/core/cgraph.c b/librz/core/cgraph.c index 2f149cc9762..cbf825567a4 100644 --- a/librz/core/cgraph.c +++ b/librz/core/cgraph.c @@ -9,7 +9,8 @@ #include #include #include "core_private.h" -#include +#include +#include #include #include #include @@ -1357,18 +1358,17 @@ RZ_API RZ_OWN RzGraph /**/ *rz_core_graph_cfg_iwords(RZ_NONNU } // Add all neighbors to graph RzAnalysisInsnWord target_iword = { 0 }; - SetUIter it; - set_u_iter_reset(it); - set_u_foreach(cur_iword.jump_targets, it) { - ut64 target = it.v; + RzIterator *iter = rz_set_u_as_iter(cur_iword.jump_targets); + ut64 *target; + rz_iterator_foreach(iter, target) { rz_analysis_insn_word_setup(&target_iword); - if (decode_iword_at(core, target, buf, sizeof(buf), &target_iword) <= 0) { + if (decode_iword_at(core, *target, buf, sizeof(buf), &target_iword) <= 0) { rz_analysis_insn_word_fini(&target_iword); continue; } - bool target_within_fcn = fcn ? rz_analysis_function_contains(fcn, target) : true; + bool target_within_fcn = fcn ? rz_analysis_function_contains(fcn, *target) : true; bool found = false; - ht_uu_find(nodes_visited, target, &found); + ht_uu_find(nodes_visited, *target, &found); if (!found && target_within_fcn) { rz_vector_push(to_visit, &target); } diff --git a/librz/include/rz_analysis.h b/librz/include/rz_analysis.h index 5672ff09ee7..74d27a0a289 100644 --- a/librz/include/rz_analysis.h +++ b/librz/include/rz_analysis.h @@ -1002,8 +1002,8 @@ typedef struct { ut64 addr; ///< Address the instruction word is located. RzStrBuf *asm_str; ///< The whole asm string. Single instructions are separated by a newline. RzPVector /**/ *insns; ///< Instructions forming the instruction word. - SetU *jump_targets; ///< Set of addresses this iword possibly jumps to. This includes the next instr. word if there is any. - SetU *call_targets; ///< Set of addresses this iword calls. + RzSetU *jump_targets; ///< Set of addresses this iword possibly jumps to. This includes the next instr. word if there is any. + RzSetU *call_targets; ///< Set of addresses this iword calls. RzAnalysisLiftedILOp il_op; ///< The complete IL operation of this instr. word. RzAnalysisIWordProperties props; ///< Properties of this instruction word. } RzAnalysisInsnWord; diff --git a/librz/util/set.c b/librz/util/set.c index 7e8bb6f14c3..5e561dcf23d 100644 --- a/librz/util/set.c +++ b/librz/util/set.c @@ -99,14 +99,6 @@ RZ_API void rz_set_u_add(RZ_NONNULL RzSetU *set, ut64 u) { ht_up_insert(set, u, (void *)1); } -/** - * \brief Get the size of set \s. - */ -RZ_API ut64 set_u_size(SetU *s) { - rz_return_val_if_fail(s, 0); - return s->count; -} - /** * \brief Check if hash set \p set contains element \p u. */ diff --git a/test/unit/test_util.c b/test/unit/test_util.c index 959a51cc272..a9f302bb1d4 100644 --- a/test/unit/test_util.c +++ b/test/unit/test_util.c @@ -2,7 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only #include -#include +#include #include "minunit.h" bool test_file_slurp(void) { @@ -63,80 +63,7 @@ bool test_leading_zeros(void) { mu_end; } -bool test_set_u(void) { - SetU *set_u = set_u_new(); - set_u_add(set_u, 0x5050505); - set_u_add(set_u, 0x5050505); - set_u_add(set_u, 0x6060606); - set_u_add(set_u, 0x7070707); - set_u_add(set_u, 0x7070707); - mu_assert_eq(set_u_size(set_u), 3, "Length wrong."); - mu_assert_true(set_u_contains(set_u, 0x5050505), "Value was not added."); - mu_assert_true(set_u_contains(set_u, 0x6060606), "Value was not added."); - mu_assert_true(set_u_contains(set_u, 0x7070707), "Value was not added."); - - set_u_delete(set_u, 0x7070707); - mu_assert_false(set_u_contains(set_u, 0x7070707), "Value was not deleted."); - mu_assert_eq(set_u_size(set_u), 2, "Length wrong."); - - // Double delete - set_u_delete(set_u, 0x7070707); - mu_assert_eq(set_u_size(set_u), 2, "Length wrong."); - - size_t x = 0; - SetUIter it; - set_u_iter_reset(it); - set_u_foreach(set_u, it) { - x++; - bool matches = it.v == 0x5050505 || it.v == 0x6060606; - mu_assert_true(matches, "Set contained ill-formed value."); - } - mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times."); - - set_u_delete(set_u, 0x6060606); - mu_assert_eq(set_u_size(set_u), 1, "Length wrong."); - set_u_delete(set_u, 0x5050505); - mu_assert_eq(set_u_size(set_u), 0, "Length wrong."); - - set_u_iter_reset(it); - set_u_foreach(set_u, it) { - mu_assert("Should not be reached.", false); - } - set_u_add(set_u, 0x53e0); - set_u_add(set_u, 0x53bc); - x = 0; - set_u_iter_reset(it); - set_u_foreach(set_u, it) { - x++; - } - mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times."); - set_u_delete(set_u, 0x53e0); - set_u_delete(set_u, 0x53bc); - - set_u_add(set_u, 0); - set_u_add(set_u, 1); - set_u_add(set_u, 2); - set_u_add(set_u, 3); - - // Add an address as key which is far away from the heap addresses. - set_u_add(set_u, 100000000); - mu_assert_true(set_u_contains(set_u, 100000000), "Not contained."); - mu_assert_eq(set_u->count, 5, "count"); - mu_assert_false(set_u_contains(set_u, 6), "should not be here."); - - x = 0; - set_u_iter_reset(it); - set_u_foreach(set_u, it) { - x++; - } - mu_assert_eq(x, 5, "Foreach hasn't iterated the correct number of times."); - - set_u_free(set_u); - mu_end; -} - int all_tests() { - mu_run_test(test_set_u); mu_run_test(test_file_slurp); mu_run_test(test_leading_zeros); return tests_passed != tests_run;