Skip to content

Commit

Permalink
Fix assert and improve code for r_core_anal_hasrefs_to_depth
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Sep 1, 2019
1 parent 774dde3 commit c380d94
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions libr/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2050,27 +2050,32 @@ static int is_string (const ut8 *buf, int size, int *len) {
static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth);
R_API char *r_core_anal_hasrefs(RCore *core, ut64 value, bool verbose) {
if (verbose) {
return r_core_anal_hasrefs_to_depth (core, value, r_config_get_i (core->config, "hex.depth"));
const int hex_depth = r_config_get_i (core->config, "hex.depth");
return r_core_anal_hasrefs_to_depth (core, value, hex_depth);
}
RFlagItem *fi = r_flag_get_i (core->flags, value);
if (fi) {
return strdup (fi->name);
}
return NULL;
return fi? strdup (fi->name): NULL;
}

static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) {
r_return_val_if_fail (core && value != UT64_MAX, NULL);
if (depth < 1) {
return NULL;
}
RStrBuf *s = r_strbuf_new (NULL);
char *mapname = NULL;
RFlagItem *fi = r_flag_get_i (core->flags, value);
ut64 type = r_core_anal_address (core, value);
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, value, 0);
if (value && value != UT64_MAX) {
RDebugMap *map = r_debug_map_get (core->dbg, value);
if (map && map->name && map->name[0]) {
mapname = strdup (map->name);
}
}
if (mapname) {
r_strbuf_appendf (s, " (%s)", mapname);
R_FREE (mapname);
}
int bits = core->assembler->bits;
switch (bits) {
case 16: // umf, not in sync with pxr
Expand Down Expand Up @@ -2107,17 +2112,14 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) {
if (sect && sect->name[0]) {
r_strbuf_appendf (s," (%s)", sect->name);
}
if (mapname) {
r_strbuf_appendf (s, " (%s)", mapname);
R_FREE (mapname);
}
}
if (fi) {
RRegItem *r = r_reg_get (core->dbg->reg, fi->name, -1);
if (!r) {
r_strbuf_appendf (s, " %s", fi->name);
}
}
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, value, 0);
if (fcn) {
r_strbuf_appendf (s, " %s", fcn->name);
}
Expand Down

0 comments on commit c380d94

Please sign in to comment.