* [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions @ 2013-01-07 20:38 Nickolai Zeldovich 2013-01-07 21:36 ` Richard Henderson 2013-01-08 9:03 ` Stefan Hajnoczi 0 siblings, 2 replies; 10+ messages in thread From: Nickolai Zeldovich @ 2013-01-07 20:38 UTC (permalink / raw) To: qemu-devel; +Cc: Nickolai Zeldovich memcpy() for overlapping regions is undefined behavior; use memmove() instead in readline_hist_add(). Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> --- 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 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-07 20:38 [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions Nickolai Zeldovich @ 2013-01-07 21:36 ` Richard Henderson 2013-01-08 9:03 ` Stefan Hajnoczi 1 sibling, 0 replies; 10+ messages in thread From: Richard Henderson @ 2013-01-07 21:36 UTC (permalink / raw) To: Nickolai Zeldovich; +Cc: qemu-devel, Stefan Hajnoczi On 01/07/2013 12:38 PM, Nickolai Zeldovich wrote: > memcpy() for overlapping regions is undefined behavior; use memmove() > instead in readline_hist_add(). > > Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> > --- > readline.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) This probably should go in via trivial... Reviewed-by: Richard Henderson <rth@twiddle.net> r~ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-07 20:38 [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions Nickolai Zeldovich 2013-01-07 21:36 ` Richard Henderson @ 2013-01-08 9:03 ` Stefan Hajnoczi 2013-01-09 20:43 ` Blue Swirl 1 sibling, 1 reply; 10+ messages in thread From: Stefan Hajnoczi @ 2013-01-08 9:03 UTC (permalink / raw) To: Nickolai Zeldovich; +Cc: qemu-devel On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: > memcpy() for overlapping regions is undefined behavior; use memmove() > instead in readline_hist_add(). > > Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> > --- > readline.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) I made a slight modification: keep the tab characters since the surrounding code still uses them. Thanks, applied to the trivial patches tree: https://github.com/stefanha/qemu/commits/trivial-patches Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-08 9:03 ` Stefan Hajnoczi @ 2013-01-09 20:43 ` Blue Swirl 2013-01-10 12:43 ` Stefan Hajnoczi 0 siblings, 1 reply; 10+ messages in thread From: Blue Swirl @ 2013-01-09 20:43 UTC (permalink / raw) To: Stefan Hajnoczi; +Cc: Nickolai Zeldovich, qemu-devel On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: >> memcpy() for overlapping regions is undefined behavior; use memmove() >> instead in readline_hist_add(). >> >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> >> --- >> readline.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) > > I made a slight modification: keep the tab characters since the > surrounding code still uses them. I think tabs should be fixed whenever possible, otherwise we may never get them converted. > > Thanks, applied to the trivial patches tree: > https://github.com/stefanha/qemu/commits/trivial-patches > > Stefan > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-09 20:43 ` Blue Swirl @ 2013-01-10 12:43 ` Stefan Hajnoczi 2013-01-12 10:46 ` Blue Swirl 0 siblings, 1 reply; 10+ messages in thread From: Stefan Hajnoczi @ 2013-01-10 12:43 UTC (permalink / raw) To: Blue Swirl; +Cc: Nickolai Zeldovich, qemu-devel On Wed, Jan 09, 2013 at 08:43:51PM +0000, Blue Swirl wrote: > On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: > >> memcpy() for overlapping regions is undefined behavior; use memmove() > >> instead in readline_hist_add(). > >> > >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> > >> --- > >> readline.c | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > > > > I made a slight modification: keep the tab characters since the > > surrounding code still uses them. > > I think tabs should be fixed whenever possible, otherwise we may never > get them converted. Not in a one-line patch when the surrounding lines still use them. It creates a mess. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-10 12:43 ` Stefan Hajnoczi @ 2013-01-12 10:46 ` Blue Swirl 2013-01-14 9:09 ` Stefan Hajnoczi 0 siblings, 1 reply; 10+ messages in thread From: Blue Swirl @ 2013-01-12 10:46 UTC (permalink / raw) To: Stefan Hajnoczi; +Cc: Nickolai Zeldovich, qemu-devel On Thu, Jan 10, 2013 at 12:43 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > On Wed, Jan 09, 2013 at 08:43:51PM +0000, Blue Swirl wrote: >> On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: >> > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: >> >> memcpy() for overlapping regions is undefined behavior; use memmove() >> >> instead in readline_hist_add(). >> >> >> >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> >> >> --- >> >> readline.c | 4 ++-- >> >> 1 file changed, 2 insertions(+), 2 deletions(-) >> > >> > I made a slight modification: keep the tab characters since the >> > surrounding code still uses them. >> >> I think tabs should be fixed whenever possible, otherwise we may never >> get them converted. > > Not in a one-line patch when the surrounding lines still use them. It > creates a mess. Only if the reader messes with the tab width settings (and in that case they deserve what they get and they are probably also used to this), otherwise a line with tabs converted to spaces looks exactly the same. I think this is identical case to braces. If we don't allow mass conversion, conversion as a side effect is the only way and then it should be always followed. > > Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-12 10:46 ` Blue Swirl @ 2013-01-14 9:09 ` Stefan Hajnoczi 2013-01-17 20:13 ` Blue Swirl 0 siblings, 1 reply; 10+ messages in thread From: Stefan Hajnoczi @ 2013-01-14 9:09 UTC (permalink / raw) To: Blue Swirl; +Cc: Nickolai Zeldovich, qemu-devel On Sat, Jan 12, 2013 at 10:46:18AM +0000, Blue Swirl wrote: > On Thu, Jan 10, 2013 at 12:43 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > > On Wed, Jan 09, 2013 at 08:43:51PM +0000, Blue Swirl wrote: > >> On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > >> > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: > >> >> memcpy() for overlapping regions is undefined behavior; use memmove() > >> >> instead in readline_hist_add(). > >> >> > >> >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> > >> >> --- > >> >> readline.c | 4 ++-- > >> >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> > > >> > I made a slight modification: keep the tab characters since the > >> > surrounding code still uses them. > >> > >> I think tabs should be fixed whenever possible, otherwise we may never > >> get them converted. > > > > Not in a one-line patch when the surrounding lines still use them. It > > creates a mess. > > Only if the reader messes with the tab width settings (and in that > case they deserve what they get and they are probably also used to > this), otherwise a line with tabs converted to spaces looks exactly > the same. You are oversimplifying how tab widths work. The author and reader's tab width must match in order for displayed text to appear correctly. Tell me what you consider the "correct" tab width for readers and I'll find a piece of QEMU code that was authored for a different tab width :). In other words, it's a mess and best not to perturb it further. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-14 9:09 ` Stefan Hajnoczi @ 2013-01-17 20:13 ` Blue Swirl 2013-01-18 11:04 ` Stefan Hajnoczi 0 siblings, 1 reply; 10+ messages in thread From: Blue Swirl @ 2013-01-17 20:13 UTC (permalink / raw) To: Stefan Hajnoczi; +Cc: Nickolai Zeldovich, qemu-devel On Mon, Jan 14, 2013 at 9:09 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > On Sat, Jan 12, 2013 at 10:46:18AM +0000, Blue Swirl wrote: >> On Thu, Jan 10, 2013 at 12:43 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote: >> > On Wed, Jan 09, 2013 at 08:43:51PM +0000, Blue Swirl wrote: >> >> On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: >> >> > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: >> >> >> memcpy() for overlapping regions is undefined behavior; use memmove() >> >> >> instead in readline_hist_add(). >> >> >> >> >> >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> >> >> >> --- >> >> >> readline.c | 4 ++-- >> >> >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> > >> >> > I made a slight modification: keep the tab characters since the >> >> > surrounding code still uses them. >> >> >> >> I think tabs should be fixed whenever possible, otherwise we may never >> >> get them converted. >> > >> > Not in a one-line patch when the surrounding lines still use them. It >> > creates a mess. >> >> Only if the reader messes with the tab width settings (and in that >> case they deserve what they get and they are probably also used to >> this), otherwise a line with tabs converted to spaces looks exactly >> the same. > > You are oversimplifying how tab widths work. The author and reader's > tab width must match in order for displayed text to appear correctly. Exactly. The default tab width is 8 in all tools and it takes some effort to adjust the tab settings in each tool. For example, how do you change it in less, xterm or cmd.exe? It is unreasonable and arrogant for an author to assume any other setting used by the reader for tab width, even if this was declared for example at the start of the file. Perhaps an analogy could be a compressing or encrypting preprocessor for the white space in the code. Without the right tool and correct settings, the reader would not see the white space in the code correctly. > Tell me what you consider the "correct" tab width for readers and I'll > find a piece of QEMU code that was authored for a different tab width > :). 8. > > In other words, it's a mess and best not to perturb it further. No, those messes should be cleaned up, much like braces. > > Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-17 20:13 ` Blue Swirl @ 2013-01-18 11:04 ` Stefan Hajnoczi 2013-01-19 9:04 ` Blue Swirl 0 siblings, 1 reply; 10+ messages in thread From: Stefan Hajnoczi @ 2013-01-18 11:04 UTC (permalink / raw) To: Blue Swirl; +Cc: Nickolai Zeldovich, qemu-devel On Thu, Jan 17, 2013 at 08:13:38PM +0000, Blue Swirl wrote: > On Mon, Jan 14, 2013 at 9:09 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > > On Sat, Jan 12, 2013 at 10:46:18AM +0000, Blue Swirl wrote: > >> On Thu, Jan 10, 2013 at 12:43 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > >> > On Wed, Jan 09, 2013 at 08:43:51PM +0000, Blue Swirl wrote: > >> >> On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > >> >> > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: > >> >> >> memcpy() for overlapping regions is undefined behavior; use memmove() > >> >> >> instead in readline_hist_add(). > >> >> >> > >> >> >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> > >> >> >> --- > >> >> >> readline.c | 4 ++-- > >> >> >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> >> > > >> >> > I made a slight modification: keep the tab characters since the > >> >> > surrounding code still uses them. > >> >> > >> >> I think tabs should be fixed whenever possible, otherwise we may never > >> >> get them converted. > >> > > >> > Not in a one-line patch when the surrounding lines still use them. It > >> > creates a mess. > >> > >> Only if the reader messes with the tab width settings (and in that > >> case they deserve what they get and they are probably also used to > >> this), otherwise a line with tabs converted to spaces looks exactly > >> the same. > > > > You are oversimplifying how tab widths work. The author and reader's > > tab width must match in order for displayed text to appear correctly. > > Exactly. The default tab width is 8 in all tools and it takes some > effort to adjust the tab settings in each tool. For example, how do > you change it in less, xterm or cmd.exe? > > It is unreasonable and arrogant for an author to assume any other > setting used by the reader for tab width, even if this was declared > for example at the start of the file. > > Perhaps an analogy could be a compressing or encrypting preprocessor > for the white space in the code. Without the right tool and correct > settings, the reader would not see the white space in the code > correctly. > > > Tell me what you consider the "correct" tab width for readers and I'll > > find a piece of QEMU code that was authored for a different tab width > > :). > > 8. > > > > > In other words, it's a mess and best not to perturb it further. > > No, those messes should be cleaned up, much like braces. Agreed but in cleanup patches or when touching the whole function. Not one line at a time because then we have an even bigger mess. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions 2013-01-18 11:04 ` Stefan Hajnoczi @ 2013-01-19 9:04 ` Blue Swirl 0 siblings, 0 replies; 10+ messages in thread From: Blue Swirl @ 2013-01-19 9:04 UTC (permalink / raw) To: Stefan Hajnoczi; +Cc: Nickolai Zeldovich, qemu-devel On Fri, Jan 18, 2013 at 11:04 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: > On Thu, Jan 17, 2013 at 08:13:38PM +0000, Blue Swirl wrote: >> On Mon, Jan 14, 2013 at 9:09 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: >> > On Sat, Jan 12, 2013 at 10:46:18AM +0000, Blue Swirl wrote: >> >> On Thu, Jan 10, 2013 at 12:43 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote: >> >> > On Wed, Jan 09, 2013 at 08:43:51PM +0000, Blue Swirl wrote: >> >> >> On Tue, Jan 8, 2013 at 9:03 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote: >> >> >> > On Mon, Jan 07, 2013 at 03:38:39PM -0500, Nickolai Zeldovich wrote: >> >> >> >> memcpy() for overlapping regions is undefined behavior; use memmove() >> >> >> >> instead in readline_hist_add(). >> >> >> >> >> >> >> >> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu> >> >> >> >> --- >> >> >> >> readline.c | 4 ++-- >> >> >> >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> >> > >> >> >> > I made a slight modification: keep the tab characters since the >> >> >> > surrounding code still uses them. >> >> >> >> >> >> I think tabs should be fixed whenever possible, otherwise we may never >> >> >> get them converted. >> >> > >> >> > Not in a one-line patch when the surrounding lines still use them. It >> >> > creates a mess. >> >> >> >> Only if the reader messes with the tab width settings (and in that >> >> case they deserve what they get and they are probably also used to >> >> this), otherwise a line with tabs converted to spaces looks exactly >> >> the same. >> > >> > You are oversimplifying how tab widths work. The author and reader's >> > tab width must match in order for displayed text to appear correctly. >> >> Exactly. The default tab width is 8 in all tools and it takes some >> effort to adjust the tab settings in each tool. For example, how do >> you change it in less, xterm or cmd.exe? >> >> It is unreasonable and arrogant for an author to assume any other >> setting used by the reader for tab width, even if this was declared >> for example at the start of the file. >> >> Perhaps an analogy could be a compressing or encrypting preprocessor >> for the white space in the code. Without the right tool and correct >> settings, the reader would not see the white space in the code >> correctly. >> >> > Tell me what you consider the "correct" tab width for readers and I'll >> > find a piece of QEMU code that was authored for a different tab width >> > :). >> >> 8. >> >> > >> > In other words, it's a mess and best not to perturb it further. >> >> No, those messes should be cleaned up, much like braces. > > Agreed but in cleanup patches or when touching the whole function. Not > one line at a time because then we have an even bigger mess. So you are advocating cleanup patches which only adjust formatting? How about mass conversion then? Anthony has rejected the similar approach for braces because of the loss of git blame info. > > Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-01-19 9:05 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-01-07 20:38 [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions Nickolai Zeldovich 2013-01-07 21:36 ` Richard Henderson 2013-01-08 9:03 ` Stefan Hajnoczi 2013-01-09 20:43 ` Blue Swirl 2013-01-10 12:43 ` Stefan Hajnoczi 2013-01-12 10:46 ` Blue Swirl 2013-01-14 9:09 ` Stefan Hajnoczi 2013-01-17 20:13 ` Blue Swirl 2013-01-18 11:04 ` Stefan Hajnoczi 2013-01-19 9:04 ` Blue Swirl
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).