From b13547d821af5c24195fe58e040654992c589d86 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 22 Nov 2017 21:49:56 +0100 Subject: [PATCH] =?utf8?q?re=20PR=20libgomp/83106=20(libgomp/target.c:2671?= =?utf8?q?:2:=20error:=20=E2=80=98strncat=E2=80=99=20specified=20bound=205?= =?utf8?q?=20equals=20source=20length=20[-Werror=3Dstringop-overflow=3D])?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 6 ++++++ libgomp/target.c | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 2299ed968fb..9999b060234 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,9 @@ +2017-11-22 Jakub Jelinek + + 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 * configure.ac: Set CET_FLAGS, update XCFLAGS and FCFLAGS. 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)) { -- 2.30.2