Skip to contentSkip to conversation

perf symbol: Avoid an undefined behavior warning

PATCH Applied Ian Rogers 2 participants 2 messages Sep 14, 2023 – Sep 17, 2023 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf symbol: Avoid an undefined behavior warning

The node (nd) may be NULL and pointer arithmetic on NULL is undefined behavior. Move the computation of next below the NULL check on the node.

---
 tools/perf/util/symbol.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/symbol.c +1 -2
index 3f36675b7c8f..5b54d2639df4 100644
@@ -202,11 +202,10 @@ void symbols__fixup_duplicate(struct rb_root_cached *symbols)
 		curr = rb_entry(nd, struct symbol, rb_node);
 again:
 		nd = rb_next(&curr->rb_node);
-		next = rb_entry(nd, struct symbol, rb_node);
-
 		if (!nd)
 			break;
 
+		next = rb_entry(nd, struct symbol, rb_node);
 		if (curr->start != next->start)
 			continue;
 
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
maintainer Applied
#1 lore raw
Quoted 6 lines · Ian Rogers

The node (nd) may be NULL and pointer arithmetic on NULL is undefined behavior. Move the computation of next below the NULL check on the node.

Applied to perf-tools-next, thanks!

Namhyung