From mboxrd@z Thu Jan 1 00:00:00 1970 From: andy at warmcat.com (Andy Green) Date: Tue, 26 Jun 2018 19:36:30 +0800 Subject: [PATCH v2 1/2] gcc8.1: fix strncpy bounds warnings In-Reply-To: <153001243122.15144.2264749610797891759.stgit@mail.warmcat.com> References: <153001243122.15144.2264749610797891759.stgit@mail.warmcat.com> Message-ID: <153001299022.15144.1325335174388192168.stgit@mail.warmcat.com> These warnings are coming on default Fedora 28 build and probably others using gcc 8.1 ../shared.c: In function ?expand_macro?: ../shared.c:483:3: warning: ?strncpy? specified bound depends on the length of the source argument [-Wstringop-overflow=] strncpy(name, value, len); ^~~~~~~~~~~~~~~~~~~~~~~~~ ../shared.c:480:9: note: length computed here len = strlen(value); ^~~~~~~~~~~~~ strncpy with a computed length via strlen is usually not the right thing. Signed-off-by: Andy Green --- shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared.c b/shared.c index d7c7636..6cda79e 100644 --- a/shared.c +++ b/shared.c @@ -483,7 +483,7 @@ static char *expand_macro(char *name, int maxlength) len = strlen(value); if (len > maxlength) len = maxlength; - strncpy(name, value, len); + memcpy(name, value, len); } return name + len; }