On Mon, Nov 20, 2017 at 02:58:49PM +0100, Martin Liška wrote: > Hello. > > This is fix of compilation error I see with > --enable-offload-targets=nvptx-none=. It's explained > in very detail way here: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83007#c1 > > Ready for trunk? > Martin > > libgomp/ChangeLog: > > 2017-11-20 Martin Liska <mli...@suse.cz> > > * target.c (gomp_target_init): Use proper string operation. > --- > libgomp/target.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-)
I've instead committed this version after bootstrapping/regtesting it on x86_64-linux and i686-linux: 2017-11-22 Jakub Jelinek <ja...@redhat.com> PR libgomp/83106 * target.c (gomp_target_init): Compute lengths just once and use them in both malloc size and subsequent copying. --- libgomp/target.c.jj 2017-10-28 09:02:06.000000000 +0200 +++ libgomp/target.c 2017-11-22 13:54:56.250444247 +0100 @@ -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)) { Jakub