xstrsncpy: allow 0 len copies to be no-ops

This commit is contained in:
NRK 2025-01-05 19:17:18 +00:00
parent da73d9ada9
commit a0c06d0843

View file

@ -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 */
}