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: Nickolai Zeldovich <nickolai@csail.mit.edu> Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
8e4a424b30
commit
7682e85807
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user