summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-09-20 21:25:48 +0200
committerMike Yuan <me@yhndnzj.com>2024-09-20 22:44:34 +0200
commit47941afd1757ed1cfd50faa364fd9624e3a6e892 (patch)
tree7976c5aca890b5aee11ff44ffd8dfab8f51431b6
parentbasic: replace size_multiply_overflow() with MUL_ASSIGN_SAFE where applicable (diff)
downloadsystemd-47941afd1757ed1cfd50faa364fd9624e3a6e892.tar.xz
systemd-47941afd1757ed1cfd50faa364fd9624e3a6e892.zip
basic/memory-util: make mempcpy_typesafe() take number of obj rather than raw size
Follow-up for eda6223942a172fa6777901cf5fbd47438f285ce
-rw-r--r--src/basic/memory-util.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/basic/memory-util.h b/src/basic/memory-util.h
index 2e10d33bb3..1f604cc452 100644
--- a/src/basic/memory-util.h
+++ b/src/basic/memory-util.h
@@ -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) {