From: Namhyung Kim <namhyung@kernel.org>
To: Yanteng Si <siyanteng@loongson.cn>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
mark.rutland@arm.com, adrian.hunter@intel.com,
linux-perf-users@vger.kernel.org,
Sun Haiyong <sunhaiyong@loongson.cn>
Subject: Re: [PATCH] objtool/perf: Fix malloc call for new -Walloc-size
Date: Sat, 2 Dec 2023 16:56:04 -0800 [thread overview]
Message-ID: <CAM9d7cjFhVag8nTjtkJvz63vgm+-NbKRhf1Z7OVRWUfgLWCgVA@mail.gmail.com> (raw)
In-Reply-To: <20231202023256.3398906-1-siyanteng@loongson.cn>
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
>
next prev parent reply other threads:[~2023-12-03 0:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-02 2:32 [PATCH] objtool/perf: Fix malloc call for new -Walloc-size Yanteng Si
2023-12-03 0:56 ` Namhyung Kim [this message]
2023-12-04 8:05 ` Yanteng Si
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAM9d7cjFhVag8nTjtkJvz63vgm+-NbKRhf1Z7OVRWUfgLWCgVA@mail.gmail.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=siyanteng@loongson.cn \
--cc=sunhaiyong@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).