From: Nickolai Zeldovich <[email protected]>

memcpy() for overlapping regions is undefined behavior; use memmove()
instead in readline_hist_add().

[Keep tab characters since surrounding code still uses them -- Stefan]

Signed-off-by: Nickolai Zeldovich <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
---
 readline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/readline.c b/readline.c
index 5fc9643..a0c9638 100644
--- a/readline.c
+++ b/readline.c
@@ -248,8 +248,8 @@ static void readline_hist_add(ReadLineState *rs, const char 
*cmdline)
     if (idx == READLINE_MAX_CMDS) {
        /* Need to get one free slot */
        free(rs->history[0]);
-       memcpy(rs->history, &rs->history[1],
-              (READLINE_MAX_CMDS - 1) * sizeof(char *));
+       memmove(rs->history, &rs->history[1],
+               (READLINE_MAX_CMDS - 1) * sizeof(char *));
        rs->history[READLINE_MAX_CMDS - 1] = NULL;
        idx = READLINE_MAX_CMDS - 1;
     }
-- 
1.8.0.2


Reply via email to