]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cli.c
env in ram
[z180-stamp.git] / avr / cli.c
index 01ad81b9048ae138e5274addeff6fcf1d173037d..be5df40deb6c2d393d59ef7799eb53b862f42940 100644 (file)
--- a/avr/cli.c
+++ b/avr/cli.c
@@ -181,11 +181,11 @@ static int cli_run_command(const char *cmd, int flag)
        if (!cmd || !*cmd)
                return -1;      /* empty command */
 
-
-       cmdbuf = xmalloc(strlen(cmd) + 1);
+       cmdbuf = strdup(cmd);
        finaltoken = xmalloc(CONFIG_SYS_CBSIZE);
+       if (!finaltoken)
+               return -1;      /* not enough memory */
 
-       strcpy(cmdbuf, cmd);
        str = cmdbuf;
 
        /* Process separators and check for invalid
@@ -309,11 +309,8 @@ void cli_loop(void)
 
                flag = 0;       /* assume no special flags for now */
                if (len > 0) {
-                       lastcommand = (char *) xrealloc(lastcommand, len+1);
-                       if (lastcommand != NULL) {
-                               strncpy(lastcommand, console_buffer, len+1);
-                               lastcommand[len] = '\0';
-                       }
+                       free (lastcommand);
+                       lastcommand = strdup(console_buffer);
                } else if (len == 0)
                        flag |= CMD_FLAG_REPEAT;