diff mbox

target-arm: default empty semihosting cmdline

Message ID AC7B5AFC-06AE-4FAD-9852-B65708E80E09@livius.net
State New
Headers show

Commit Message

Liviu Ionescu June 21, 2015, 7:24 a.m. UTC
If neither explicit semihosting args nor -kernel are used, 
make SYS_GET_CMDLINE return an empty string.

Signed-off-by: Liviu Ionescu <ilg@livius.net>
---
 target-arm/arm-semi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Liviu Ionescu June 22, 2015, 8:51 p.m. UTC | #1
Peter, it looks like I forgot to Cc: you for this patch:

> On 21 Jun 2015, at 10:24, Liviu Ionescu <ilg@livius.net> wrote:
> 
> If neither explicit semihosting args nor -kernel are used, 
> make SYS_GET_CMDLINE return an empty string.
> 
> Signed-off-by: Liviu Ionescu <ilg@livius.net>
> ---
> target-arm/arm-semi.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c
> index 74a67e9..a2a7369 100644
> --- a/target-arm/arm-semi.c
> +++ b/target-arm/arm-semi.c
> @@ -436,12 +436,19 @@ uint32_t do_arm_semihosting(CPUARMState *env)
>             size_t input_size;
>             size_t output_size;
>             int status = 0;
> +#if !defined(CONFIG_USER_ONLY)
> +            const char *cmdline;
> +#endif
>             GET_ARG(0);
>             GET_ARG(1);
>             input_size = arg1;
>             /* Compute the size of the output string.  */
> #if !defined(CONFIG_USER_ONLY)
> -            output_size = strlen(semihosting_get_cmdline()) + 1;
> +            cmdline = semihosting_get_cmdline();
> +            if (cmdline == NULL) {
> +                cmdline = ""; /* Default to an empty line. */
> +            }
> +            output_size = strlen(cmdline) + 1; /* Count terminating 0. */
> #else
>             unsigned int i;
> 
> @@ -472,7 +479,7 @@ uint32_t do_arm_semihosting(CPUARMState *env)
> 
>             /* Copy the command-line arguments.  */
> #if !defined(CONFIG_USER_ONLY)
> -            pstrcpy(output_buffer, output_size, semihosting_get_cmdline());
> +            pstrcpy(output_buffer, output_size, cmdline);
> #else
>             if (output_size == 1) {
>                 /* Empty command-line.  */
> -- 
> 2.3.2 (Apple Git-55)
> 
>
Peter Maydell June 23, 2015, 4:06 p.m. UTC | #2
On 21 June 2015 at 08:24, Liviu Ionescu <ilg@livius.net> wrote:
> If neither explicit semihosting args nor -kernel are used,
> make SYS_GET_CMDLINE return an empty string.
>
> Signed-off-by: Liviu Ionescu <ilg@livius.net>
> ---
>  target-arm/arm-semi.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)



Applied to target-arm.next, thanks.

-- PMM
diff mbox

Patch

diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c
index 74a67e9..a2a7369 100644
--- a/target-arm/arm-semi.c
+++ b/target-arm/arm-semi.c
@@ -436,12 +436,19 @@  uint32_t do_arm_semihosting(CPUARMState *env)
             size_t input_size;
             size_t output_size;
             int status = 0;
+#if !defined(CONFIG_USER_ONLY)
+            const char *cmdline;
+#endif
             GET_ARG(0);
             GET_ARG(1);
             input_size = arg1;
             /* Compute the size of the output string.  */
 #if !defined(CONFIG_USER_ONLY)
-            output_size = strlen(semihosting_get_cmdline()) + 1;
+            cmdline = semihosting_get_cmdline();
+            if (cmdline == NULL) {
+                cmdline = ""; /* Default to an empty line. */
+            }
+            output_size = strlen(cmdline) + 1; /* Count terminating 0. */
 #else
             unsigned int i;
 
@@ -472,7 +479,7 @@  uint32_t do_arm_semihosting(CPUARMState *env)
 
             /* Copy the command-line arguments.  */
 #if !defined(CONFIG_USER_ONLY)
-            pstrcpy(output_buffer, output_size, semihosting_get_cmdline());
+            pstrcpy(output_buffer, output_size, cmdline);
 #else
             if (output_size == 1) {
                 /* Empty command-line.  */