TUI: avoid calling strcpy() on identical string objects
authorPatrick Palka <patrick@parcs.ath.cx>
Sat, 25 Apr 2015 14:29:29 +0000 (10:29 -0400)
committerPatrick Palka <patrick@parcs.ath.cx>
Tue, 28 Apr 2015 01:19:58 +0000 (21:19 -0400)
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
gdb/tui/tui-source.c

index 1ff7a75..d833876 100644 (file)
@@ -1,5 +1,10 @@
 2015-04-28  Patrick Palka  <patrick@parcs.ath.cx>
 
+       * tui/tui-source.c (tui_set_source_content): Avoid calling
+       strcpy() when offset is 0.
+
+2015-04-28  Patrick Palka  <patrick@parcs.ath.cx>
+
        PR gdb/18155
        * tui/tui-data.c (tui_free_window): Don't free the locator
        window when passed an SRC_WIN or a DISASSEM_WIN.
index 31df0c8..018a1df 100644 (file)
@@ -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]);