cmdline: fix for long input
authorIntel <intel.com>
Tue, 12 Mar 2013 11:03:00 +0000 (12:03 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 25 Jul 2013 14:07:50 +0000 (16:07 +0200)
Signed-off-by: Intel
lib/librte_cmdline/cmdline_rdline.c

index 0f99e61..1d0e51b 100644 (file)
@@ -118,9 +118,10 @@ rdline_newline(struct rdline *rdl, const char *prompt)
        cirbuf_init(&rdl->left, rdl->left_buf, 0, RDLINE_BUF_SIZE);
        cirbuf_init(&rdl->right, rdl->right_buf, 0, RDLINE_BUF_SIZE);
 
+       rdl->prompt_size = strnlen(prompt, RDLINE_PROMPT_SIZE-1);
        if (prompt != rdl->prompt)
-               memcpy(rdl->prompt, prompt, sizeof(rdl->prompt)-1);
-       rdl->prompt_size = strnlen(prompt, RDLINE_PROMPT_SIZE);
+               memcpy(rdl->prompt, prompt, rdl->prompt_size);
+       rdl->prompt[RDLINE_PROMPT_SIZE-1] = '\0';
 
        for (i=0 ; i<rdl->prompt_size ; i++)
                rdl->write_char(rdl, rdl->prompt[i]);