qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions


From: Nickolai Zeldovich
Subject: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions
Date: Mon, 7 Jan 2013 15:38:39 -0500

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

Signed-off-by: Nickolai Zeldovich <address@hidden>
---
 readline.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/readline.c b/readline.c
index 5fc9643..aeccc7b 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.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]