Skip to content

Commit

Permalink
Fix build errors from conflict resolving.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed May 18, 2024
1 parent 1db1687 commit a5d3972
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 71 deletions.
2 changes: 1 addition & 1 deletion librz/bin/format/pe/pe_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ RzPVector /*<char *>*/ *PE_(rz_bin_pe_get_libs)(RzBinPEObj *bin) {
}
}
RzPVector *vec = rz_set_s_to_vector(libs);
set_s_free(libs);
rz_set_s_free(libs);
return vec;
}

Expand Down
4 changes: 2 additions & 2 deletions librz/core/cmd/cmd_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ RZ_API RZ_OWN RzPVector /*<char *>*/ *rz_core_get_themes(RZ_NONNULL RzCore *core

RzPVector *vec = rz_set_s_to_vector(themes);
if (!vec) {
set_s_free(themes);
rz_set_s_free(themes);
return NULL;
}
rz_pvector_push(vec, strdup("default"));
rz_pvector_sort(vec, (RzPVectorComparator)compare_strings, NULL);
set_s_free(themes);
rz_set_s_free(themes);
return vec;
}

Expand Down
5 changes: 5 additions & 0 deletions librz/util/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ static bool push_to_pvector(void *user, const char *k, RZ_UNUSED const void *v)
return !!rz_pvector_push(vec, (void *)k);
}


RZ_API void rz_set_s_free(RZ_NULLABLE RzSetS *set) {
ht_sp_free((HtSP *)set);
}

/**
* \brief Create a vector from elements of hash set \p set
*
Expand Down
2 changes: 1 addition & 1 deletion test/unit/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if get_option('enable_tests')
'graph',
'hash',
'hex',
'ht',
'id_storage',
'idpool',
'idstorage',
Expand All @@ -80,7 +81,6 @@ if get_option('enable_tests')
'rz_test',
'sdb_array',
'sdb_diff',
'sdb_hash',
'sdb_sdb',
'sdb_util',
'serialize_analysis',
Expand Down
134 changes: 67 additions & 67 deletions test/unit/test_ht.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <rz_util/ht_sp.h>
#include <rz_util/ht_su.h>
#include <rz_util/ht_ss.h>
#include <rz_util/set.h>
#include <rz_util/rz_set.h>
#include <rz_util/rz_str.h>

typedef struct _test_struct {
Expand Down Expand Up @@ -690,122 +690,122 @@ bool test_ht_ss_foreach(void) {
}

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.");
RzSetU *set_u = rz_set_u_new();
rz_set_u_add(set_u, 0x5050505);
rz_set_u_add(set_u, 0x5050505);
rz_set_u_add(set_u, 0x6060606);
rz_set_u_add(set_u, 0x7070707);
rz_set_u_add(set_u, 0x7070707);
mu_assert_eq(rz_set_u_size(set_u), 3, "Length wrong.");
mu_assert_true(rz_set_u_contains(set_u, 0x5050505), "Value was not added.");
mu_assert_true(rz_set_u_contains(set_u, 0x6060606), "Value was not added.");
mu_assert_true(rz_set_u_contains(set_u, 0x7070707), "Value was not added.");

rz_set_u_delete(set_u, 0x7070707);
mu_assert_false(rz_set_u_contains(set_u, 0x7070707), "Value was not deleted.");
mu_assert_eq(rz_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.");
rz_set_u_delete(set_u, 0x7070707);
mu_assert_eq(rz_set_u_size(set_u), 2, "Length wrong.");

size_t x = 0;
SetUIter it;
set_u_foreach (set_u, it) {
RzSetUIter it;
rz_set_u_foreach (set_u, it) {
x++;
bool matches = it.kv->key == 0x5050505 || it.kv->key == 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.");
rz_set_u_delete(set_u, 0x6060606);
mu_assert_eq(rz_set_u_size(set_u), 1, "Length wrong.");
rz_set_u_delete(set_u, 0x5050505);
mu_assert_eq(rz_set_u_size(set_u), 0, "Length wrong.");

set_u_foreach (set_u, it) {
rz_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);
rz_set_u_add(set_u, 0x53e0);
rz_set_u_add(set_u, 0x53bc);
x = 0;
set_u_foreach (set_u, it) {
rz_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);
rz_set_u_delete(set_u, 0x53e0);
rz_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);
rz_set_u_add(set_u, 0);
rz_set_u_add(set_u, 1);
rz_set_u_add(set_u, 2);
rz_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.");
rz_set_u_add(set_u, 100000000);
mu_assert_true(rz_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.");
mu_assert_false(rz_set_u_contains(set_u, 6), "should not be here.");

x = 0;
set_u_foreach (set_u, it) {
rz_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);
rz_set_u_free(set_u);
mu_end;
}


bool test_set_s(void) {
SetS *set_s = set_s_new(HT_STR_CONST);
set_s_add(set_s, "0x5050505");
set_s_add(set_s, "0x5050505");
set_s_add(set_s, "0x6060606");
set_s_add(set_s, "0x7070707");
set_s_add(set_s, "0x7070707");
mu_assert_eq(set_s_size(set_s), 3, "Length wrong.");
mu_assert_true(set_s_contains(set_s, "0x5050505"), "Value was not added.");
mu_assert_true(set_s_contains(set_s, "0x6060606"), "Value was not added.");
mu_assert_true(set_s_contains(set_s, "0x7070707"), "Value was not added.");

set_s_delete(set_s, "0x7070707");
mu_assert_false(set_s_contains(set_s, "0x7070707"), "Value was not deleted.");
mu_assert_eq(set_s_size(set_s), 2, "Length wrong.");
RzSetS *set_s = rz_set_s_new(HT_STR_CONST);
rz_set_s_add(set_s, "0x5050505");
rz_set_s_add(set_s, "0x5050505");
rz_set_s_add(set_s, "0x6060606");
rz_set_s_add(set_s, "0x7070707");
rz_set_s_add(set_s, "0x7070707");
mu_assert_eq(rz_set_s_size(set_s), 3, "Length wrong.");
mu_assert_true(rz_set_s_contains(set_s, "0x5050505"), "Value was not added.");
mu_assert_true(rz_set_s_contains(set_s, "0x6060606"), "Value was not added.");
mu_assert_true(rz_set_s_contains(set_s, "0x7070707"), "Value was not added.");

rz_set_s_delete(set_s, "0x7070707");
mu_assert_false(rz_set_s_contains(set_s, "0x7070707"), "Value was not deleted.");
mu_assert_eq(rz_set_s_size(set_s), 2, "Length wrong.");

// Double delete
set_s_delete(set_s, "0x7070707");
mu_assert_eq(set_s_size(set_s), 2, "Length wrong.");
rz_set_s_delete(set_s, "0x7070707");
mu_assert_eq(rz_set_s_size(set_s), 2, "Length wrong.");

size_t x = 0;
SetSIter it;
set_s_foreach (set_s, it) {
RzSetSIter it;
rz_set_s_foreach (set_s, it) {
x++;
bool matches = RZ_STR_EQ(it.kv->key, "0x5050505") || RZ_STR_EQ(it.kv->key, "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_s_delete(set_s, "0x6060606");
mu_assert_eq(set_s_size(set_s), 1, "Length wrong.");
set_s_delete(set_s, "0x5050505");
mu_assert_eq(set_s_size(set_s), 0, "Length wrong.");
rz_set_s_delete(set_s, "0x6060606");
mu_assert_eq(rz_set_s_size(set_s), 1, "Length wrong.");
rz_set_s_delete(set_s, "0x5050505");
mu_assert_eq(rz_set_s_size(set_s), 0, "Length wrong.");

set_s_foreach (set_s, it) {
rz_set_s_foreach (set_s, it) {
mu_assert("Should not be reached.", false);
}
set_s_add(set_s, "0x53e0");
set_s_add(set_s, "0x53bc");
rz_set_s_add(set_s, "0x53e0");
rz_set_s_add(set_s, "0x53bc");
x = 0;
set_s_foreach (set_s, it) {
rz_set_s_foreach (set_s, it) {
x++;
}
mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times.");
set_s_delete(set_s, "0x53e0");
set_s_delete(set_s, "0x53bc");
rz_set_s_delete(set_s, "0x53e0");
rz_set_s_delete(set_s, "0x53bc");

set_s_free(set_s);
rz_set_s_free(set_s);
mu_end;
}

Expand Down

0 comments on commit a5d3972

Please sign in to comment.