Explorar o código

perf tests: Do not use sizeof on pointer type

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>
Vaishali Thakkar %!s(int64=9) %!d(string=hai) anos
pai
achega
ca7ce82a28
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      tools/perf/tests/dso-data.c

+ 1 - 1
tools/perf/tests/dso-data.c

@@ -202,7 +202,7 @@ static int dsos__create(int cnt, int size)
 {
 {
 	int i;
 	int i;
 
 
-	dsos = malloc(sizeof(dsos) * cnt);
+	dsos = malloc(sizeof(*dsos) * cnt);
 	TEST_ASSERT_VAL("failed to alloc dsos array", dsos);
 	TEST_ASSERT_VAL("failed to alloc dsos array", dsos);
 
 
 	for (i = 0; i < cnt; i++) {
 	for (i = 0; i < cnt; i++) {