The nr_entries variable is increased inside the loop in the function
but it also counts when hists__filter_entries() returns NULL.  Thus
the end result will have actual count + 1.

It'd become a problem especially there's no entry at all - it'd get a
segfault during referencing a NULL pointer.

Signed-off-by: Namhyung Kim <[email protected]>
---
 tools/perf/ui/browsers/hists.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 4d416984c59d..e86b95cc55db 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1349,9 +1349,10 @@ static void hist_browser__update_pcnt_entries(struct 
hist_browser *hb)
        struct rb_node *nd = rb_first(&hb->hists->entries);
 
        while (nd) {
-               nr_entries++;
                nd = hists__filter_entries(rb_next(nd), hb->hists,
                                           hb->min_pcnt);
+               if (nd)
+                       nr_entries++;
        }
 
        hb->nr_pcnt_entries = nr_entries;
-- 
1.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to