public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] TUI: avoid calling strcpy() on indentical string objects
@ 2015-04-26 15:17 Patrick Palka
  2015-04-27 17:51 ` Pedro Alves
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2015-04-26 15:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: Patrick Palka

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/tui/tui-source.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 31df0c8..018a1df 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.4.0.rc2.31.g7c597ef

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] TUI: avoid calling strcpy() on indentical string objects
  2015-04-26 15:17 [PATCH] TUI: avoid calling strcpy() on indentical string objects Patrick Palka
@ 2015-04-27 17:51 ` Pedro Alves
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2015-04-27 17:51 UTC (permalink / raw)
  To: Patrick Palka, gdb-patches

On 04/26/2015 04:17 PM, Patrick Palka wrote:
> 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.

OK.

Boy is that code messy.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-27 17:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-26 15:17 [PATCH] TUI: avoid calling strcpy() on indentical string objects Patrick Palka
2015-04-27 17:51 ` Pedro Alves

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 read-only IMAP folder(s) and NNTP newsgroup(s).