From 9e640fb14e669f9128b90d28c136b2eed88162b8 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 21 Jan 2024 11:01:45 -0800 Subject: [PATCH] gcc warning fix Avoid two new warnings in xname_flags() about strncpy() not supplying a terminating '\0'. That's exactly why strncpy() was being used. The gcc manual lists -Wno-stringop-truncation to suppress the warning but not -Wstringup-truncation to voluntarily enable it, so the pragma stuff in warnings.h probably won't work for this. Just switch from strncpy() to memcpy() instead even though it seems like obfuscation. --- src/objnam.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/objnam.c b/src/objnam.c index b80a79142..c0626c1a8 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -910,8 +910,9 @@ xname_flags( if (buf_eos > buf_end) { /* PREFIX is bigger than 6 so there will always be room within the obuf[] in front of buf to insert "buf[]="; strncpy(,,N) doesn't - add '\0' terminator unless fewer than N chars are copied */ - paniclog("xname", strncpy(buf - 6, "buf[]=", 6)); + add '\0' terminator unless fewer than N chars are copied, which + is what we want, but gcc complains about that so use memcpy() */ + paniclog("xname", (char *) memcpy(buf - 6, "buf[]=", 6)); panic("xname: buffer overflow before appending name."); /*NOTREACHED*/ } @@ -979,7 +980,7 @@ xname_flags( anticipated; since we aren't panicking here, this could happen repeatedly and we don't want to spam the paniclog file */ if (!xname_full++) { - paniclog("xname", strncpy(buf - 6, "buf[]=", 6)); + paniclog("xname", (char *) memcpy(buf - 6, "buf[]=", 6)); /* 'PREFIX' ought to be 'PREFIX+4' if we stripped leading "the" */ paniclog("xname", "used up entire obuf[PREFIX..BUFSX-1]"); }