Misplaced parenthesis calculates two too few bytes for string
authorAlan Modra <amodra@gmail.com>
Sun, 28 Dec 2014 04:58:19 +0000 (15:28 +1030)
committerAlan Modra <amodra@gmail.com>
Sun, 28 Dec 2014 05:04:01 +0000 (15:34 +1030)
Factor out strlen to give better code and less likelihood of a repeat
of this problem.

PR 17766
* pei-x86_64.c (pex64_bfd_print_pdata_section): Correct string
length.  Use memcpy rather than strcpy.

bfd/ChangeLog
bfd/pei-x86_64.c

index 7b3a4740c1ec7878ffecbcdbe63bef39bef8d3eb..b883d3c6d2c763b0d8b81d79309fc8bbb8107861 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-28  Alan Modra  <amodra@gmail.com>
+
+       PR 17766
+       * pei-x86_64.c (pex64_bfd_print_pdata_section): Correct string
+       length.  Use memcpy rather than strcpy.
+
 2014-12-26  Alan Modra  <amodra@gmail.com>
 
        PR 17755
index 51bf39046cbe02a6ff892b78282888f03cda387a..2009a2962a742ab704baa75291ae9cf589ef4dd4 100644 (file)
@@ -601,11 +601,12 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
      section name, replacing .pdata by .xdata prefix.  */
   if (strcmp (pdata_section->name, ".pdata") != 0)
     {
-      char *xdata_name = alloca (strlen (pdata_section->name + 1));
+      size_t len = strlen (pdata_section->name);
+      char *xdata_name = alloca (len + 1);
 
-      xdata_name = strcpy (xdata_name, pdata_section->name);
+      xdata_name = memcpy (xdata_name, pdata_section->name, len + 1);
       /* Transform .pdata prefix into .xdata prefix.  */
-      if (strlen (xdata_name) > 1)
+      if (len > 1)
        xdata_name [1] = 'x';
       xdata_section = pex64_get_section_by_rva (abfd, xdata_base,
                                                xdata_name);
This page took 0.0264 seconds and 4 git commands to generate.