Minor code cleanups/fixes (#12714)

This commit is contained in:
dav1901 2019-01-09 23:06:12 +02:00 committed by radare
parent ba6d256bec
commit 37ea17d1a2
7 changed files with 14 additions and 46 deletions

View File

@ -47,10 +47,7 @@ enum {
};
static int strcmpnull(const char *a, const char *b) {
if (!a || !b) {
return -1;
}
return strcmp (a, b);
return (a && b) ? strcmp (a, b) : -1;
}
// static const char *const arm_shift[] = {"lsl", "lsr", "asr", "ror"};

View File

@ -777,7 +777,6 @@ R_API RList *r_bin_patch_relocs(RBin *bin) {
o->relocs = tmp;
REBASE_PADDR (o, o->relocs, RBinReloc);
first = false;
return o->relocs;
}
return o->relocs;
}

View File

@ -6,16 +6,23 @@
static char *hashify(char *s, ut64 vaddr) {
r_return_val_if_fail (s, NULL);
char *ret;
char *os = s;
while (*s) {
if (!IS_PRINTABLE (*s)) {
if (vaddr && vaddr != UT64_MAX) {
free (os);
return r_str_newf ("_%" PFMT64d, vaddr);
ret = r_str_newf ("_%" PFMT64d, vaddr);
if (ret) {
free (os);
}
return ret;
}
ut32 hash = sdb_hash (s);
free (os);
return r_str_newf ("%x", hash);
ret = r_str_newf ("%x", hash);
if (ret) {
free (os);
}
return ret;
}
s++;
}

View File

@ -808,6 +808,7 @@ static int cmd_type(void *data, const char *input) {
}
if (name && (r_type_kind (TDB, name) != R_TYPE_ENUM)) {
eprintf ("%s is not an enum\n", name);
free (name);
break;
}
switch (input[1]) {

View File

@ -435,7 +435,6 @@ R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len);
/* io/section.c */
R_API void r_io_section_init (RIO *io);
R_API void r_io_section_fini (RIO *io);
R_API int r_io_section_exists_for_id (RIO *io, ut32 id);
R_API RIOSection *r_io_section_add (RIO *io, ut64 addr, ut64 vaddr, ut64 size, ut64 vsize, int rwx, const char *name, ut32 bin_id, int fd);
R_API RIOSection *r_io_section_get_i (RIO *io, ut32 id);
R_API SdbList *r_io_section_bin_get (RIO *io, ut32 bin_id);
@ -449,7 +448,6 @@ R_API bool r_io_section_apply (RIO *io, ut32 id, RIOSectionApplyMethod method);
R_API bool r_io_section_apply_bin (RIO *io, ut32 bin_id, RIOSectionApplyMethod method);
R_API RIOSection* r_io_section_get(RIO *io, ut64 paddr);
R_API RIOSection* r_io_section_vget(RIO *io, ut64 vaddr);
R_API ut64 r_io_section_get_paddr_at(RIO *io, ut64 addr);
/* io/p_cache.c */
R_API bool r_io_desc_cache_init (RIODesc *desc);

View File

@ -37,20 +37,6 @@ R_API void r_io_section_fini(RIO *io) {
io->sec_ids = NULL;
}
R_API int r_io_section_exists_for_id(RIO *io, ut32 id) {
SdbListIter *iter;
RIOSection *sec;
if (!io || !io->sections) {
return false;
}
ls_foreach (io->sections, iter, sec) {
if (sec->id == id) {
return true;
}
}
return false;
}
R_API RIOSection *r_io_section_add(RIO *io, ut64 paddr, ut64 vaddr, ut64 size,
ut64 vsize, int perm, const char *name,
ut32 bin_id, int fd) {
@ -217,22 +203,6 @@ R_API RIOSection* r_io_section_get(RIO *io, ut64 vaddr) {
return NULL;
}
R_API ut64 r_io_section_get_paddr_at(RIO *io, ut64 paddr) {
if (io) {
SdbList *sects = r_io_sections_get (io, paddr);
ut64 ret = UT64_MAX;
if (sects) {
if (!ls_empty (sects)) {
RIOSection *s = ls_pop (sects);
ret = s->paddr;
}
}
ls_free (sects);
return ret;
}
return UT64_MAX;
}
R_API const char *r_io_section_get_archbits(RIO *io, ut64 vaddr, int *bits) {
if (!io) {
return NULL;

View File

@ -12,11 +12,7 @@ SDB_API SdbList *ls_newf(SdbListFree freefn) {
}
SDB_API SdbList *ls_new() {
SdbList *list = R_NEW0 (SdbList);
if (!list) {
return NULL;
}
return list;
return R_NEW0 (SdbList);
}
static void ls_insertion_sort_iter(SdbListIter *iter, SdbListComparator cmp) {