re PR libgomp/83106 (libgomp/target.c:2671:2: error: ‘strncat’ specified bound 5...
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Nov 2017 20:49:56 +0000 (21:49 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 22 Nov 2017 20:49:56 +0000 (21:49 +0100)
PR libgomp/83106
* target.c (gomp_target_init): Compute lengths just once and
use them in both malloc size and subsequent copying.

From-SVN: r255080

libgomp/ChangeLog
libgomp/target.c

index 2299ed9..9999b06 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR libgomp/83106
+       * target.c (gomp_target_init): Compute lengths just once and
+       use them in both malloc size and subsequent copying.
+
 2017-11-17  Igor Tsimbalist  <igor.v.tsimbalist@intel.com>
 
        * configure.ac: Set CET_FLAGS, update XCFLAGS and FCFLAGS.
index 8ac05e8..4c0f4fc 100644 (file)
@@ -2656,20 +2656,24 @@ gomp_target_init (void)
     do
       {
        struct gomp_device_descr current_device;
+       size_t prefix_len, suffix_len, cur_len;
 
        next = strchr (cur, ',');
 
-       plugin_name = (char *) malloc (1 + (next ? next - cur : strlen (cur))
-                                      + strlen (prefix) + strlen (suffix));
+       prefix_len = strlen (prefix);
+       cur_len = next ? next - cur : strlen (cur);
+       suffix_len = strlen (suffix);
+
+       plugin_name = (char *) malloc (prefix_len + cur_len + suffix_len + 1);
        if (!plugin_name)
          {
            num_devices = 0;
            break;
          }
 
-       strcpy (plugin_name, prefix);
-       strncat (plugin_name, cur, next ? next - cur : strlen (cur));
-       strcat (plugin_name, suffix);
+       memcpy (plugin_name, prefix, prefix_len);
+       memcpy (plugin_name + prefix_len, cur, cur_len);
+       memcpy (plugin_name + prefix_len + cur_len, suffix, suffix_len + 1);
 
        if (gomp_load_plugin_for_device (&current_device, plugin_name))
          {