if (offset < len)
hits = sym->hist[offset];
- if (sym_ext) {
+ if (offset < len && sym_ext) {
path = sym_ext[offset].path;
percent = sym_ext[offset].percent;
} else if (sym->hist_sum)
}
/* Get the filename:line for the colored entries */
-static void get_source_line(struct symbol *sym, __u64 start, int len)
+static void
+get_source_line(struct symbol *sym, __u64 start, int len, char *filename)
{
int i;
char cmd[PATH_MAX * 2];
continue;
offset = start + i;
- sprintf(cmd, "addr2line -e %s %016llx", vmlinux, offset);
+ sprintf(cmd, "addr2line -e %s %016llx", filename, offset);
fp = popen(cmd, "r");
if (!fp)
continue;
if (getline(&path, &line_len, fp) < 0 || !line_len)
goto next;
- sym_ext[i].path = malloc(sizeof(char) * line_len);
+ sym_ext[i].path = malloc(sizeof(char) * line_len + 1);
if (!sym_ext[i].path)
goto next;
len = sym->end - sym->start;
if (print_line) {
- get_source_line(sym, start, len);
+ get_source_line(sym, start, len, filename);
print_summary(filename);
}