From: Paul Eggert Date: Mon, 31 Jul 2023 18:21:25 +0000 (-0700) Subject: who: fix only-theoretical overflow X-Git-Tag: v9.4~60 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9cbda6e1f8fdd4d7ffae26edcabceb239ed14ece;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/src/system.h b/src/system.h index db1a6773b9..2d9c47f48b 100644 --- a/src/system.h +++ b/src/system.h @@ -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;