From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>, qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
qemu-arm@nongnu.org, "Glenn Miles" <milesg@linux.ibm.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
"Daniel P . Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH 3/4] tests/unit/test-char: Avoid using g_alloca()
Date: Fri, 6 Jun 2025 09:18:34 -0700 [thread overview]
Message-ID: <811aa1ec-352d-40cb-a42b-2bca5dcf64cd@linaro.org> (raw)
In-Reply-To: <0f7673d9-31f4-495b-a118-f53ed6c6fc37@linaro.org>
On 6/5/25 11:09 PM, Philippe Mathieu-Daudé wrote:
> On 5/6/25 22:53, Pierrick Bouvier wrote:
>> On 6/5/25 12:35 PM, Philippe Mathieu-Daudé wrote:
>>> Do not use g_alloca(), simply allocate the CharBackend
>>> structure on the stack.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> ---
>>> tests/unit/test-char.c | 3 +--
>>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c
>>> index 60a843b79d9..f30a39f61ff 100644
>>> --- a/tests/unit/test-char.c
>>> +++ b/tests/unit/test-char.c
>>> @@ -993,7 +993,7 @@ static void char_udp_test_internal(Chardev
>>> *reuse_chr, int sock)
>>> struct sockaddr_in other;
>>> SocketIdleData d = { 0, };
>>> Chardev *chr;
>>> - CharBackend *be;
>>> + CharBackend stack_be, *be = &stack_be;
>>> socklen_t alen = sizeof(other);
>>> int ret;
>>> char buf[10];
>>> @@ -1009,7 +1009,6 @@ static void char_udp_test_internal(Chardev
>>> *reuse_chr, int sock)
>>> chr = qemu_chr_new("client", tmp, NULL);
>>> g_assert_nonnull(chr);
>>> - be = g_alloca(sizeof(CharBackend));
>>> qemu_chr_fe_init(be, chr, &error_abort);
>>> }
>>
>> Would that be more simple to declare the variable, and use &be in the
>> function code?
>
> More context (see reuse_chr ladder):
>
> -- >8 --
> @@ -991,45 +991,44 @@ static int make_udp_socket(int *port)
> static void char_udp_test_internal(Chardev *reuse_chr, int sock)
> {
> struct sockaddr_in other;
> SocketIdleData d = { 0, };
> Chardev *chr;
> - CharBackend *be;
> + CharBackend stack_be, *be = &stack_be;
> socklen_t alen = sizeof(other);
> int ret;
> char buf[10];
> char *tmp = NULL;
>
> if (reuse_chr) {
> chr = reuse_chr;
> be = chr->be;
> } else {
> int port;
> sock = make_udp_socket(&port);
> tmp = g_strdup_printf("udp:127.0.0.1:%d", port);
> chr = qemu_chr_new("client", tmp, NULL);
> g_assert_nonnull(chr);
>
> - be = g_alloca(sizeof(CharBackend));
> qemu_chr_fe_init(be, chr, &error_abort);
> }
> ---
Ok!
next prev parent reply other threads:[~2025-06-06 16:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 19:35 [PATCH 0/4] system: Forbid alloca() Philippe Mathieu-Daudé
2025-06-05 19:35 ` [PATCH 1/4] hw/gpio/pca9552: Avoid using g_newa() Philippe Mathieu-Daudé
2025-06-05 21:03 ` Miles Glenn
2025-06-05 19:35 ` [PATCH 2/4] backends/tpmL Avoid using g_alloca() Philippe Mathieu-Daudé
2025-06-05 21:23 ` BALATON Zoltan
2025-06-06 7:00 ` Philippe Mathieu-Daudé
2025-06-06 8:14 ` Thomas Huth
2025-06-08 19:09 ` Stefan Berger
2025-06-08 19:07 ` Stefan Berger
2025-06-05 19:35 ` [PATCH 3/4] tests/unit/test-char: " Philippe Mathieu-Daudé
2025-06-05 20:53 ` Pierrick Bouvier
2025-06-06 6:09 ` Philippe Mathieu-Daudé
2025-06-06 16:18 ` Pierrick Bouvier [this message]
2025-06-05 19:35 ` [RFC PATCH 4/4] buildsys: Prohibit alloca() use on system code Philippe Mathieu-Daudé
2025-06-05 20:53 ` [PATCH 0/4] system: Forbid alloca() Pierrick Bouvier
2025-06-06 8:37 ` Peter Maydell
2025-06-06 8:53 ` Philippe Mathieu-Daudé
2025-06-06 8:44 ` Alex Bennée
2025-06-09 13:46 ` Stefan Hajnoczi
2025-06-10 9:29 ` Philippe Mathieu-Daudé
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=811aa1ec-352d-40cb-a42b-2bca5dcf64cd@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=milesg@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=stefanb@linux.vnet.ibm.com \
--cc=stefanha@redhat.com \
/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).