From a0c06d0843a7dd8c8e2603913cd0d33c1efa78ea Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 5 Jan 2025 19:17:18 +0000 Subject: [PATCH] xstrsncpy: allow 0 len copies to be no-ops --- src/nnn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nnn.c b/src/nnn.c index 5c7e136f..81af4c5b 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -988,7 +988,8 @@ static size_t xstrsncpy(char *restrict dst, const char *restrict src, size_t n) char *end = memccpy(dst, src, '\0', n); if (!end) { - dst[n - 1] = '\0'; // NOLINT + if (n) + dst[n - 1] = '\0'; end = dst + n; /* If we return n here, binary size increases due to auto-inlining */ }