* [PATCH] perf tests: Do not use sizeof on pointer type
@ 2016-04-28 16:46 Vaishali Thakkar
2016-04-28 18:36 ` Arnaldo Carvalho de Melo
2016-05-01 7:41 ` [tip:perf/core] " tip-bot for Vaishali Thakkar
0 siblings, 2 replies; 3+ messages in thread
From: Vaishali Thakkar @ 2016-04-28 16:46 UTC (permalink / raw)
To: peterz; +Cc: mingo, acme, alexander.shishkin, linux-kernel, Vaishali Thakkar
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>
---
tools/perf/tests/dso-data.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index dc673ff..8cf0d9e 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -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++) {
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf tests: Do not use sizeof on pointer type
2016-04-28 16:46 [PATCH] perf tests: Do not use sizeof on pointer type Vaishali Thakkar
@ 2016-04-28 18:36 ` Arnaldo Carvalho de Melo
2016-05-01 7:41 ` [tip:perf/core] " tip-bot for Vaishali Thakkar
1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-28 18:36 UTC (permalink / raw)
To: Vaishali Thakkar; +Cc: peterz, mingo, alexander.shishkin, linux-kernel
Em Thu, Apr 28, 2016 at 10:16:57PM +0530, Vaishali Thakkar escreveu:
> 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.
Thanks, applied.
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:perf/core] perf tests: Do not use sizeof on pointer type
2016-04-28 16:46 [PATCH] perf tests: Do not use sizeof on pointer type Vaishali Thakkar
2016-04-28 18:36 ` Arnaldo Carvalho de Melo
@ 2016-05-01 7:41 ` tip-bot for Vaishali Thakkar
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Vaishali Thakkar @ 2016-05-01 7:41 UTC (permalink / raw)
To: linux-tip-commits
Cc: peterz, vaishali.thakkar, linux-kernel, hpa, acme, mingo, tglx,
alexander.shishkin
Commit-ID: ca7ce82a280a65c377c24c95c29b1dec6e80b428
Gitweb: http://git.kernel.org/tip/ca7ce82a280a65c377c24c95c29b1dec6e80b428
Author: Vaishali Thakkar <vaishali.thakkar@oracle.com>
AuthorDate: Thu, 28 Apr 2016 22:16:57 +0530
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 15:37:52 -0300
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>
---
tools/perf/tests/dso-data.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index dc673ff..8cf0d9e 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -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++) {
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-01 7:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-28 16:46 [PATCH] perf tests: Do not use sizeof on pointer type Vaishali Thakkar
2016-04-28 18:36 ` Arnaldo Carvalho de Melo
2016-05-01 7:41 ` [tip:perf/core] " tip-bot for Vaishali Thakkar
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.