From cd8d2039b01382a49054f2e3e0c9196e2dba5c0c Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 7 Dec 2020 17:16:46 +1030 Subject: [GOLD] gcc-11 stringop-overflow warning I'm unsure why this is deserving of a warning. Not writing the most efficient code surely can't be a real problem, but that is what https://gcc.gnu.org/bugzilla//show_bug.cgi?id=88059#c1 seems to say. plugin.cc:528:10: error: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 528 | strncpy(tempdir, dir_template, len); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ plugin.cc:526:22: note: length computed here 526 | size_t len = strlen(dir_template) + 1; | ~~~~~~^~~~~~~~~~~~~~ * plugin.cc (Plugin_recorder::init): Replace strncpy with memcpy. --- gold/plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gold/plugin.cc') diff --git a/gold/plugin.cc b/gold/plugin.cc index 729ddca9f31..fd37957e73c 100644 --- a/gold/plugin.cc +++ b/gold/plugin.cc @@ -525,7 +525,7 @@ Plugin_recorder::init() size_t len = strlen(dir_template) + 1; char* tempdir = new char[len]; - strncpy(tempdir, dir_template, len); + memcpy(tempdir, dir_template, len); // Create the log file. std::string logname(tempdir); -- cgit v1.2.1