linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tools/perf: Fix malloc call for new -Walloc-size
@ 2023-12-04  8:20 Yanteng Si
  2024-01-26 14:31 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Yanteng Si @ 2023-12-04  8:20 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 set it to NULL, silence this error.

Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
---
v2:

* Refer to Namhyung's comment and set it to NULL.

 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..3960c4d15eff 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 = NULL, *p;
 	size_t dummy = 0;
 	int tmp;
 
-- 
2.31.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] tools/perf: Fix malloc call for new -Walloc-size
  2023-12-04  8:20 [PATCH v2] tools/perf: Fix malloc call for new -Walloc-size Yanteng Si
@ 2024-01-26 14:31 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-01-26 14:31 UTC (permalink / raw)
  To: Yanteng Si
  Cc: peterz, mingo, alexander.shishkin, jolsa, mark.rutland, namhyung,
	adrian.hunter, linux-perf-users, Sun Haiyong

Em Mon, Dec 04, 2023 at 04:20:55PM +0800, Yanteng Si escreveu:
> 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 set it to NULL, silence this error.

Thanks, applied to perf-tools.

Changed the subject to:

  perf top: Remove needless malloc(0) call that triggers -Walloc-size

And the last line of the log to:

  Just set it to NULL, getline() will do the allocation.

- Arnaldo

 
> Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
> Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
> ---
> v2:
> 
> * Refer to Namhyung's comment and set it to NULL.
> 
>  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..3960c4d15eff 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 = NULL, *p;
>  	size_t dummy = 0;
>  	int tmp;
>  
> -- 
> 2.31.4
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-26 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04  8:20 [PATCH v2] tools/perf: Fix malloc call for new -Walloc-size Yanteng Si
2024-01-26 14:31 ` Arnaldo Carvalho de Melo

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).