std-aux: add nm_memcpy() helper for handling copy of zero bytes

This commit is contained in:
Thomas Haller 2022-09-29 08:33:35 +02:00
parent 50b6f3d6d3
commit 263832a455
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -501,6 +501,17 @@ nm_memeq(const void *s1, const void *s2, size_t len)
return nm_memcmp(s1, s2, len) == 0;
}
static inline void *
nm_memcpy(void *restrict dest, const void *restrict src, size_t n)
{
/* Workaround undefined behavior in memcpy() with NULL pointers. */
if (n == 0)
return dest;
nm_assert(src);
return memcpy(dest, src, n);
}
/*
* Very similar to g_str_has_prefix() with the obvious meaning.
* Differences: