From 0f6b118fbe9010c10940eeb00407b9e1f0ed4963 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 13 Dec 2024 19:28:46 +1100 Subject: [PATCH] use memcpy (recommended) instead of stpncpy to avoid spurious gcc warnings --- src/util.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util.c b/src/util.c index 0fbd026..a0cb1dd 100644 --- a/src/util.c +++ b/src/util.c @@ -31,17 +31,20 @@ char *string_replace(const char * const src, const char * const target, const ch while ((match = strstr(s, target))) { // copy up to match - r = stpncpy(r, s, match - s); + memcpy(r, s, match - s); + r += match - s; // copy replacement - r = stpncpy(r, replacement, len_replacement); + memcpy(r, replacement, len_replacement); + r += len_replacement; // advance src to after match s = match + len_target; } - // copy remainder - r = stpncpy(r, s, len_res - (r - res) - 1); + // copy remainder, ensuring terminated + memcpy(r, s, len_res - (r - res) - 1); + res[len_res - 1] = '\0'; return res; }