StringUtils: fix a possible segfault

This commit is contained in:
李通洲 2025-02-14 18:40:37 +08:00
parent fae8d1dd10
commit c081268b7c

View File

@ -83,7 +83,7 @@ static inline bool ffCharIsDigit(char c)
// Copies at most (dstBufSiz - 1) bytes from src to dst; dst is always null-terminated
static inline char* ffStrCopy(char* __restrict__ dst, const char* __restrict__ src, size_t dstBufSiz)
{
if (__builtin_expect(dst == NULL, false)) return dst;
if (__builtin_expect(dst == NULL, false) || dstBufSiz == 0) return dst;
size_t len = strnlen(src, dstBufSiz - 1);
memcpy(dst, src, len);