perf symbol: Avoid an undefined behavior warning
authorIan Rogers <irogers@google.com>
Thu, 14 Sep 2023 04:42:32 +0000 (21:42 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 15 Sep 2023 23:46:40 +0000 (16:46 -0700)
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.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20230914044233.1550195-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/symbol.c

index 3f36675b7c8ff672e23b3528e2b1a089d2dbc87e..5b54d2639df4740ead32fb860bba4c26635bcb69 100644 (file)
@@ -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;