Skip to content

Commit

Permalink
perf tests: Do not use sizeof on pointer type
Browse files Browse the repository at this point in the history
Using sizeof on a malloced pointer type will return the wordsize which
can often cause one to allocate a buffer much smaller than it is needed.
So, here do not use sizeof on pointer type.

Note that this has no effect on runtime because 'dsos' is a pointer to a
pointer.

Problem found using Coccinelle.

Signed-off-by: Vaishali Thakkar <vaishali.thakkar@oracle.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1461862017-23358-1-git-send-email-vaishali.thakkar@oracle.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Vaishali Thakkar authored and Arnaldo Carvalho de Melo committed Apr 28, 2016
1 parent a30e625 commit ca7ce82
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/perf/tests/dso-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int dsos__create(int cnt, int size)
{
int i;

dsos = malloc(sizeof(dsos) * cnt);
dsos = malloc(sizeof(*dsos) * cnt);
TEST_ASSERT_VAL("failed to alloc dsos array", dsos);

for (i = 0; i < cnt; i++) {
Expand Down

0 comments on commit ca7ce82

Please sign in to comment.