Fix compiler warning from GCC9 with -D_FORTIFY_SOURCE=2
authorFabian Keil <fk@fabiankeil.de>
Sat, 5 Dec 2020 13:33:38 +0000 (14:33 +0100)
committerFabian Keil <fk@fabiankeil.de>
Mon, 7 Dec 2020 15:01:33 +0000 (16:01 +0100)
commit27fcae78c29d538e690c745e4ca266c03e8e6e89
tree2e78e2cfa34ddfb71784f3574870b80261766d1e
parentb402d02197854c83609bb59de1365b1136703d8a
Fix compiler warning from GCC9 with -D_FORTIFY_SOURCE=2

   pcrs.c:284:14: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
     284 |       text = strncpy(text, replacement, length + 1);
         |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   pcrs.c: In function 'pcrs_compile':
   pcrs.c:268:13: note: length computed here
     268 |    length = strlen(replacement);
         |             ^~~~~~~~~~~~~~~~~~~

While the warning is correct, the length of the destination
argument also depends on the length of the source argument
so we're good.

Using strlcpy() instead of strncpy() suppresses the warning
and 'text' is filled with zeros anyway so the difference
doesn't matter.

Reported by Lee.
pcrs.c