Skip to content

Commit b352f4c

Browse files
committed
fix(Function): check if conditional jumps flows to the next instruction
1 parent a34fe6e commit b352f4c

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎src/core/function.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ static bool _rd_function_is_tail_call(const RDFunction* self,
7272
return rd_flagsbuffer_has_func(seg->flags, rd_i_address2index(seg, target));
7373
}
7474

75+
static bool _rd_function_falls_into(const RDSegment* seg, RDAddress address) {
76+
return address < rd_segment_get_end(seg) &&
77+
rd_flagsbuffer_has_flow(seg->flags,
78+
rd_i_address2index(seg, address));
79+
}
80+
7581
static RDGraphNode _rd_function_get_or_add_block(RDContext* ctx, RDGraph* g,
7682
RDAddress start,
7783
const RDFunction* func,
@@ -232,13 +238,15 @@ void rd_i_function_rebuild_graph(RDFunction* self,
232238
}
233239

234240
// false edge: fall-through
235-
RDGraphNode dst = _rd_function_get_or_add_block(
236-
ctx, g, nextaddr, self, &w, chunks);
241+
if(_rd_function_falls_into(seg, nextaddr)) {
242+
RDGraphNode dst = _rd_function_get_or_add_block(
243+
ctx, g, nextaddr, self, &w, chunks);
237244

238-
if(dst) {
239-
RDGraphEdge e = rd_graph_add_edge(g, src, dst);
240-
const char* c = rd_get_theme_color(RD_THEME_FAIL);
241-
rd_graph_set_edge_color(g, &e, c);
245+
if(dst) {
246+
RDGraphEdge e = rd_graph_add_edge(g, src, dst);
247+
const char* c = rd_get_theme_color(RD_THEME_FAIL);
248+
rd_graph_set_edge_color(g, &e, c);
249+
}
242250
}
243251
}
244252
else { // unconditional: single jump edge per target

0 commit comments

Comments
 (0)