who: fix only-theoretical overflow

Change stzncpy’s implementation to match its comment, in the case
where SRC + LEN would overflow.  This case never happens in coreutils.
* src/system.h (stzncpy): Work even if SRC + LEN would overflow.
This commit is contained in:
Paul Eggert committed 2023-07-31 11:21:43 -07:00
1 parent 779f34e180
commit 9cbda6e1f8
1 file changed
+2 -2
+2 -2
View File
@@ -781,8 +781,8 @@ write_error (void)
static inline char *
stzncpy (char *restrict dest, char const *restrict src, size_t len)
{
char const *src_end = src + len;
while (src < src_end && *src)
size_t i;
for (i = 0; i < len && *src; i++)
*dest++ = *src++;
*dest = 0;
return dest;