diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-11-22 20:49:56 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-11-22 20:49:56 +0000 |
commit | 02b7bb30d14347ed285ba5a187482ee0c66bafcf (patch) | |
tree | 8ea2827a50906a3b8399ed3ba709172ba205d005 /libgomp/target.c | |
parent | bba57a400e2510fa724b1a2250b80aae3b2fe5e4 (diff) | |
download | gcc-02b7bb30d14347ed285ba5a187482ee0c66bafcf.tar.gz |
PR libgomp/83106
* target.c (gomp_target_init): Compute lengths just once and
use them in both malloc size and subsequent copying.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255080 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgomp/target.c')
-rw-r--r-- | libgomp/target.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/libgomp/target.c b/libgomp/target.c index 8ac05e8c641..4c0f4fc9041 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -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 (¤t_device, plugin_name)) { |