Skip to content

Commit

Permalink
perf tools: Misc small fixes
Browse files Browse the repository at this point in the history
- util/header.c
	"len" is aligned to 64. So, it tries to write the out of
	long_name buffer.

	So, this use "zero_buf" to write aligned area.

- util/trace-event-read.c
	"size" is not including nul byte. So, this allocates it, and set '\0'.

- util/trace-event-parse.c
	It needs parens to calc correct size.

Signed-off-by: OGAWA Hirofumi <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
OGAWAHirofumi authored and Ingo Molnar committed Dec 6, 2009
1 parent 180f95e commit 7691b1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ static int do_write(int fd, const void *buf, size_t size)

static int __dsos__write_buildid_table(struct list_head *head, int fd)
{
#define NAME_ALIGN 64
struct dso *pos;
static const char zero_buf[NAME_ALIGN];

list_for_each_entry(pos, head, node) {
int err;
Expand All @@ -197,14 +199,17 @@ static int __dsos__write_buildid_table(struct list_head *head, int fd)
if (!pos->has_build_id)
continue;
len = pos->long_name_len + 1;
len = ALIGN(len, 64);
len = ALIGN(len, NAME_ALIGN);
memset(&b, 0, sizeof(b));
memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
b.header.size = sizeof(b) + len;
err = do_write(fd, &b, sizeof(b));
if (err < 0)
return err;
err = do_write(fd, pos->long_name, len);
err = do_write(fd, pos->long_name, pos->long_name_len + 1);
if (err < 0)
return err;
err = do_write(fd, zero_buf, len - pos->long_name_len + 1);
if (err < 0)
return err;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/trace-event-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void parse_proc_kallsyms(char *file, unsigned int size __unused)
func_count++;
}

func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));

i = 0;
while (list) {
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/util/trace-event-read.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ static void read_proc_kallsyms(void)
if (!size)
return;

buf = malloc_or_die(size);
buf = malloc_or_die(size + 1);
read_or_die(buf, size);
buf[size] = '\0';

parse_proc_kallsyms(buf, size);

Expand Down

0 comments on commit 7691b1e

Please sign in to comment.