]> granicus.if.org Git - cgit/commitdiff
gcc8.1: fix strncpy bounds warnings
authorAndy Green <andy@warmcat.com>
Tue, 26 Jun 2018 10:29:56 +0000 (18:29 +0800)
committerAndy Green <andy@warmcat.com>
Thu, 28 Jun 2018 23:53:20 +0000 (07:53 +0800)
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 <andy@warmcat.com>
shared.c

index d7c7636913a063cfc45eadab85f282a2bf5b6cc3..6cda79e189721a59c75d4bb28f76a5ebe5691d56 100644 (file)
--- 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;
 }