diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-11-22 21:49:56 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-11-22 21:49:56 +0100 |
commit | b13547d821af5c24195fe58e040654992c589d86 (patch) | |
tree | 8ea2827a50906a3b8399ed3ba709172ba205d005 | |
parent | 217e4393f7540b4f32c4eafbe3ffeceeb063eb30 (diff) | |
download | gcc-b13547d821af5c24195fe58e040654992c589d86.zip gcc-b13547d821af5c24195fe58e040654992c589d86.tar.gz gcc-b13547d821af5c24195fe58e040654992c589d86.tar.bz2 |
re PR libgomp/83106 (libgomp/target.c:2671:2: error: ‘strncat’ specified bound 5 equals source length [-Werror=stringop-overflow=])
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
-rw-r--r-- | libgomp/ChangeLog | 6 | ||||
-rw-r--r-- | libgomp/target.c | 14 |
2 files changed, 15 insertions, 5 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 2299ed9..9999b06 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -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. diff --git a/libgomp/target.c b/libgomp/target.c index 8ac05e8..4c0f4fc 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)) { |