1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 01:55:22 +03:00

basic/memory-util: make mempcpy_typesafe() take number of obj rather than raw size

Follow-up for eda6223942
This commit is contained in:
Mike Yuan 2024-09-20 21:25:48 +02:00
parent 34fb408f8b
commit 47941afd17
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3

View File

@ -35,7 +35,12 @@ static inline void* mempcpy_safe(void *dst, const void *src, size_t n) {
return mempcpy(dst, src, n);
}
#define mempcpy_typesafe(dst, src, n) (typeof((dst)[0])*) mempcpy_safe(dst, src, n)
#define mempcpy_typesafe(dst, src, n) \
({ \
size_t _sz_; \
assert_se(MUL_SAFE(&_sz_, sizeof((dst)[0]), n)); \
(typeof((dst)[0])*) mempcpy_safe(dst, src, _sz_); \
})
/* Normal memcmp() requires s1 and s2 to be nonnull. We do nothing if n is 0. */
static inline int memcmp_safe(const void *s1, const void *s2, size_t n) {