Commit 7682e858 authored by Nickolai Zeldovich's avatar Nickolai Zeldovich Committed by Stefan Hajnoczi
Browse files

readline: avoid memcpy() of overlapping regions



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: default avatarNickolai Zeldovich <nickolai@csail.mit.edu>
Reviewed-by: default avatarRichard Henderson <rth@twiddle.net>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 8e4a424b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ 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],
	memmove(rs->history, &rs->history[1],
	        (READLINE_MAX_CMDS - 1) * sizeof(char *));
	rs->history[READLINE_MAX_CMDS - 1] = NULL;
	idx = READLINE_MAX_CMDS - 1;