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 1ff7a75277d78b3d468f0cdecdfcd09f6ea949ef..d833876193d7bd8cef48253e600bdddc5228d616 100644 (file)
@@ -1,3 +1,8 @@
+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
index 31df0c8fb389ca053a91b49a14e174fcdb2685e1..018a1df8e5488b23a9031480db3c9f5a4f2f1b47 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]);