All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
Cc: qemu-devel@nongnu.org, fam@euphon.net, berrange@redhat.com,
	f4bug@amsat.org, aurelien@aurel32.net, pbonzini@redhat.com,
	stefanha@redhat.com, crosa@redhat.com, qemu-arm@nongnu.org,
	richard.henderson@linaro.org, sw@weilnetz.de
Subject: Re: [PATCH v1 7/8] semihosting: clean up handling of expanded argv
Date: Tue, 15 Mar 2022 13:59:59 +0000	[thread overview]
Message-ID: <87a6dr48n2.fsf@linaro.org> (raw)
In-Reply-To: <6c7bdb98-ad58-e48e-caa5-a9747b8ad90b@gmail.com>


Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com> writes:

> On 15/3/22 13:12, Alex Bennée wrote:
>> Another cleanup patch tripped over the fact we weren't being careful
>> in our casting. Fix the casts, allow for a non-const and switch from
>> g_realloc to g_renew.
>> The whole semihosting argument handling could do with some tests
>> though.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>>   semihosting/config.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>> diff --git a/semihosting/config.c b/semihosting/config.c
>> index 137171b717..50d82108e6 100644
>> --- a/semihosting/config.c
>> +++ b/semihosting/config.c
>> @@ -51,7 +51,7 @@ typedef struct SemihostingConfig {
>>       bool enabled;
>>       SemihostingTarget target;
>>       Chardev *chardev;
>> -    const char **argv;
>> +    char **argv;
>>       int argc;
>>       const char *cmdline; /* concatenated argv */
>>   } SemihostingConfig;
>> @@ -98,8 +98,8 @@ static int add_semihosting_arg(void *opaque,
>>       if (strcmp(name, "arg") == 0) {
>>           s->argc++;
>>           /* one extra element as g_strjoinv() expects NULL-terminated array */
>> -        s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
>> -        s->argv[s->argc - 1] = val;
>> +        s->argv = g_renew(char *, s->argv, s->argc + 1);
>> +        s->argv[s->argc - 1] = g_strdup(val);
>
> Why strdup()?

The compiler was having issues with adding a const char * into the array
and it was the quickest way to stop it complaining. I'm not sure what
guarantees you can make about a const char * after you leave the scope
of the function.

>
>>           s->argv[s->argc] = NULL;
>>       }
>>       return 0;


-- 
Alex Bennée

WARNING: multiple messages have this Message-ID (diff)
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
Cc: fam@euphon.net, berrange@redhat.com, sw@weilnetz.de,
	richard.henderson@linaro.org, qemu-devel@nongnu.org,
	f4bug@amsat.org, qemu-arm@nongnu.org, stefanha@redhat.com,
	crosa@redhat.com, pbonzini@redhat.com, aurelien@aurel32.net
Subject: Re: [PATCH v1 7/8] semihosting: clean up handling of expanded argv
Date: Tue, 15 Mar 2022 13:59:59 +0000	[thread overview]
Message-ID: <87a6dr48n2.fsf@linaro.org> (raw)
In-Reply-To: <6c7bdb98-ad58-e48e-caa5-a9747b8ad90b@gmail.com>


Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com> writes:

> On 15/3/22 13:12, Alex Bennée wrote:
>> Another cleanup patch tripped over the fact we weren't being careful
>> in our casting. Fix the casts, allow for a non-const and switch from
>> g_realloc to g_renew.
>> The whole semihosting argument handling could do with some tests
>> though.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>>   semihosting/config.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>> diff --git a/semihosting/config.c b/semihosting/config.c
>> index 137171b717..50d82108e6 100644
>> --- a/semihosting/config.c
>> +++ b/semihosting/config.c
>> @@ -51,7 +51,7 @@ typedef struct SemihostingConfig {
>>       bool enabled;
>>       SemihostingTarget target;
>>       Chardev *chardev;
>> -    const char **argv;
>> +    char **argv;
>>       int argc;
>>       const char *cmdline; /* concatenated argv */
>>   } SemihostingConfig;
>> @@ -98,8 +98,8 @@ static int add_semihosting_arg(void *opaque,
>>       if (strcmp(name, "arg") == 0) {
>>           s->argc++;
>>           /* one extra element as g_strjoinv() expects NULL-terminated array */
>> -        s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
>> -        s->argv[s->argc - 1] = val;
>> +        s->argv = g_renew(char *, s->argv, s->argc + 1);
>> +        s->argv[s->argc - 1] = g_strdup(val);
>
> Why strdup()?

The compiler was having issues with adding a const char * into the array
and it was the quickest way to stop it complaining. I'm not sure what
guarantees you can make about a const char * after you leave the scope
of the function.

>
>>           s->argv[s->argc] = NULL;
>>       }
>>       return 0;


-- 
Alex Bennée


  reply	other threads:[~2022-03-15 14:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 12:12 [PATCH for 7.0 v1 0/8] misc testing, i386, docs, gitdm, gitlab Alex Bennée
2022-03-15 12:12 ` Alex Bennée
2022-03-15 12:12 ` [PATCH v1 1/8] tests/Makefile.include: Let "make clean" remove the TCG tests, too Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-15 12:12 ` [PATCH v1 2/8] tests/avocado: update aarch64_virt test to exercise -cpu max Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-21 17:10   ` Thomas Huth
2022-03-22 16:49   ` Richard Henderson
2022-03-22 16:49     ` Richard Henderson
2022-03-15 12:12 ` [PATCH v1 3/8] target/i386: force maximum rounding precision for fildl[l] Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-15 12:12 ` [PATCH v1 4/8] tests/tcg: drop -cpu max from s390x sha512-mvx invocation Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-15 12:12 ` [PATCH v1 5/8] mailmap/gitdm: more fixes for bad tags and authors Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-16  8:23   ` Michael Ellerman
2022-03-16  8:23     ` Michael Ellerman
2022-03-15 12:12 ` [PATCH v1 6/8] docs/devel: try and impose some organisation Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-15 12:12 ` [PATCH v1 7/8] semihosting: clean up handling of expanded argv Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-15 12:31   ` Philippe Mathieu-Daudé
2022-03-15 12:31     ` Philippe Mathieu-Daudé
2022-03-15 13:59     ` Alex Bennée [this message]
2022-03-15 13:59       ` Alex Bennée
2022-03-15 14:15       ` Daniel P. Berrangé
2022-03-15 14:15         ` Daniel P. Berrangé
2022-03-15 14:20         ` Peter Maydell
2022-03-15 14:20           ` Peter Maydell
2022-03-21 21:55         ` Philippe Mathieu-Daudé
2022-03-21 21:55           ` Philippe Mathieu-Daudé
2022-03-15 12:12 ` [PATCH v1 8/8] gitlab: include new aarch32 job in custom-runners Alex Bennée
2022-03-15 12:12   ` Alex Bennée
2022-03-15 12:19   ` Alex Bennée
2022-03-15 12:19     ` Alex Bennée
2022-03-15 12:19   ` [PATCH v2] " Alex Bennée
2022-03-15 12:34     ` Philippe Mathieu-Daudé
2022-03-15 21:48     ` Richard Henderson
2022-03-21 16:46 ` [PATCH for 7.0 v1 0/8] misc testing, i386, docs, gitdm, gitlab Alex Bennée
2022-03-21 16:46   ` Alex Bennée

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=87a6dr48n2.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=aurelien@aurel32.net \
    --cc=berrange@redhat.com \
    --cc=crosa@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=fam@euphon.net \
    --cc=pbonzini@redhat.com \
    --cc=philippe.mathieu.daude@gmail.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=sw@weilnetz.de \
    /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 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.