In copy_from, don't call memmove with NULLs.

This commit is contained in:
Nigel Tao committed 2017-09-23 11:00:23 +10:00
1 parent a9f12c23a4
commit 1a28112ebd
4 files changed
+22 -4

No files matched your search

+7 -1
View File
@@ -378,9 +378,15 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is
// the minimum of dst.len and src.len.
//
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
// slice) is valid and results in a no-op.
static inline void puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
puffs_base_slice_u8 src) {
memmove(dst.ptr, src.ptr, dst.len < src.len ? dst.len : src.len);
size_t n = dst.len < src.len ? dst.len : src.len;
if (n > 0) {
memmove(dst.ptr, src.ptr, n);
}
}
#endif // PUFFS_BASE_IMPL_H
+7 -1
View File
@@ -349,9 +349,15 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is
// the minimum of dst.len and src.len.
//
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
// slice) is valid and results in a no-op.
static inline void puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
puffs_base_slice_u8 src) {
memmove(dst.ptr, src.ptr, dst.len < src.len ? dst.len : src.len);
size_t n = dst.len < src.len ? dst.len : src.len;
if (n > 0) {
memmove(dst.ptr, src.ptr, n);
}
}
#endif // PUFFS_BASE_IMPL_H