From 2eb639cbe4baa33545ca008d6054ea5db1d8f6a8 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Sat, 25 Apr 2015 10:29:29 -0400 Subject: [PATCH] TUI: avoid calling strcpy() on identical string objects In tui_set_source_content(), when offset == 0 the source and destination pointers of the call to strcpy() are actually the same. In this case not only is strcpy() unnecessary but it is also UB when the two strings overlap. gdb/ChangeLog: * tui/tui-source.c (tui_set_source_content): Avoid calling strcpy() when offset is 0. --- gdb/ChangeLog | 5 +++++ gdb/tui/tui-source.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1ff7a75277d..d833876193d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2015-04-28 Patrick Palka + + * tui/tui-source.c (tui_set_source_content): Avoid calling + strcpy() when offset is 0. + 2015-04-28 Patrick Palka PR gdb/18155 diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 31df0c8fb38..018a1df8e54 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -218,7 +218,9 @@ tui_set_source_content (struct symtab *s, } /* Now copy the line taking the offset into account. */ - if (strlen (src_line) > offset) + if (offset == 0) + ; + else if (strlen (src_line) > offset) strcpy (TUI_SRC_WIN->generic.content[cur_line] ->which_element.source.line, &src_line[offset]); -- 2.30.2