From: Fabian Keil Date: Sat, 5 Dec 2020 13:33:38 +0000 (+0100) Subject: Fix compiler warning from GCC9 with -D_FORTIFY_SOURCE=2 X-Git-Tag: v_3_0_30~271^2~63 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=27fcae78c29d538e690c745e4ca266c03e8e6e89;hp=b402d02197854c83609bb59de1365b1136703d8a 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. --- diff --git a/pcrs.c b/pcrs.c index ca6ba680..83100983 100644 --- a/pcrs.c +++ b/pcrs.c @@ -281,7 +281,7 @@ static pcrs_substitute *pcrs_compile_replacement(const char *replacement, int tr */ if (trivialflag) { - text = strncpy(text, replacement, length + 1); + strlcpy(text, replacement, length + 1); k = (int)length; }