* [PATCH] objtool/perf: Fix malloc call for new -Walloc-size
@ 2023-12-02 2:32 Yanteng Si
2023-12-03 0:56 ` Namhyung Kim
0 siblings, 1 reply; 3+ messages in thread
From: Yanteng Si @ 2023-12-02 2:32 UTC (permalink / raw)
To: peterz, mingo, acme
Cc: alexander.shishkin, jolsa, mark.rutland, namhyung, adrian.hunter,
linux-perf-users, Sun Haiyong, Yanteng Si
From: Sun Haiyong <sunhaiyong@loongson.cn>
GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
like:
```
builtin-top.c: In function ‘prompt_integer’:
builtin-top.c:360:21: error: allocation of insufficient size ‘0’ for
type ‘char’ with size ‘1’ [-Werror=alloc-size]
360 | char *buf = malloc(0), *p;
| ^~~~~~
```
So, just cast type to char, silence this error.
Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
---
tools/perf/builtin-top.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index ea8c7eca5eee..29191d966522 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -357,7 +357,7 @@ static void perf_top__print_sym_table(struct perf_top *top)
static void prompt_integer(int *target, const char *msg)
{
- char *buf = malloc(0), *p;
+ char *buf = (char *)malloc(0), *p;
size_t dummy = 0;
int tmp;
--
2.42.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] objtool/perf: Fix malloc call for new -Walloc-size
2023-12-02 2:32 [PATCH] objtool/perf: Fix malloc call for new -Walloc-size Yanteng Si
@ 2023-12-03 0:56 ` Namhyung Kim
2023-12-04 8:05 ` Yanteng Si
0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2023-12-03 0:56 UTC (permalink / raw)
To: Yanteng Si
Cc: peterz, mingo, acme, alexander.shishkin, jolsa, mark.rutland,
adrian.hunter, linux-perf-users, Sun Haiyong
Hello,
On Fri, Dec 1, 2023 at 6:33 PM Yanteng Si <siyanteng@loongson.cn> wrote:
>
> From: Sun Haiyong <sunhaiyong@loongson.cn>
>
> GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
> like:
> ```
> builtin-top.c: In function ‘prompt_integer’:
> builtin-top.c:360:21: error: allocation of insufficient size ‘0’ for
> type ‘char’ with size ‘1’ [-Werror=alloc-size]
> 360 | char *buf = malloc(0), *p;
> | ^~~~~~
>
> ```
>
> So, just cast type to char, silence this error.
No, please do not. I'm not sure if it silences the error.
The buf is to be passed to getline() so you can set it to
NULL instead.
char *buf = NULL, *p;
Thanks,
Namhyung
>
> Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
> Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
> ---
> tools/perf/builtin-top.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
> index ea8c7eca5eee..29191d966522 100644
> --- a/tools/perf/builtin-top.c
> +++ b/tools/perf/builtin-top.c
> @@ -357,7 +357,7 @@ static void perf_top__print_sym_table(struct perf_top *top)
>
> static void prompt_integer(int *target, const char *msg)
> {
> - char *buf = malloc(0), *p;
> + char *buf = (char *)malloc(0), *p;
> size_t dummy = 0;
> int tmp;
>
> --
> 2.42.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] objtool/perf: Fix malloc call for new -Walloc-size
2023-12-03 0:56 ` Namhyung Kim
@ 2023-12-04 8:05 ` Yanteng Si
0 siblings, 0 replies; 3+ messages in thread
From: Yanteng Si @ 2023-12-04 8:05 UTC (permalink / raw)
To: Namhyung Kim
Cc: peterz, mingo, acme, alexander.shishkin, jolsa, mark.rutland,
adrian.hunter, linux-perf-users, Sun Haiyong
在 2023/12/3 08:56, Namhyung Kim 写道:
> Hello,
>
> On Fri, Dec 1, 2023 at 6:33 PM Yanteng Si <siyanteng@loongson.cn> wrote:
>> From: Sun Haiyong <sunhaiyong@loongson.cn>
>>
>> GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
>> like:
>> ```
>> builtin-top.c: In function ‘prompt_integer’:
>> builtin-top.c:360:21: error: allocation of insufficient size ‘0’ for
>> type ‘char’ with size ‘1’ [-Werror=alloc-size]
>> 360 | char *buf = malloc(0), *p;
>> | ^~~~~~
>>
>> ```
>>
>> So, just cast type to char, silence this error.
> No, please do not. I'm not sure if it silences the error.
> The buf is to be passed to getline() so you can set it to
> NULL instead.
>
> char *buf = NULL, *p;
OK!
Thanks,
Yanteng
>
> Thanks,
> Namhyung
>
>> Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
>> Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
>> ---
>> tools/perf/builtin-top.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
>> index ea8c7eca5eee..29191d966522 100644
>> --- a/tools/perf/builtin-top.c
>> +++ b/tools/perf/builtin-top.c
>> @@ -357,7 +357,7 @@ static void perf_top__print_sym_table(struct perf_top *top)
>>
>> static void prompt_integer(int *target, const char *msg)
>> {
>> - char *buf = malloc(0), *p;
>> + char *buf = (char *)malloc(0), *p;
>> size_t dummy = 0;
>> int tmp;
>>
>> --
>> 2.42.1
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-04 8:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-02 2:32 [PATCH] objtool/perf: Fix malloc call for new -Walloc-size Yanteng Si
2023-12-03 0:56 ` Namhyung Kim
2023-12-04 8:05 ` Yanteng Si
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).