summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-02-15 15:50:14 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-16 08:23:58 +0100
commit507cd76085482022949fbf18c0a8da3356765967 (patch)
tree6c86c7973acdea6656393b027a8087bd66d0c5fa /src
parentdhcp-identifier: use offsetof() (diff)
downloadsystemd-507cd76085482022949fbf18c0a8da3356765967.tar.xz
systemd-507cd76085482022949fbf18c0a8da3356765967.zip
memory-util: introdyce mempcpy_safe()
Diffstat (limited to '')
-rw-r--r--src/basic/memory-util.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/basic/memory-util.h b/src/basic/memory-util.h
index 9f37431fc1..6e3280b9df 100644
--- a/src/basic/memory-util.h
+++ b/src/basic/memory-util.h
@@ -15,7 +15,7 @@ size_t page_size(void) _pure_;
#define PAGE_ALIGN_DOWN(l) ((l) & ~(page_size() - 1))
#define PAGE_OFFSET(l) ((l) & (page_size() - 1))
-/* Normal memcpy requires src to be nonnull. We do nothing if n is 0. */
+/* Normal memcpy() requires src to be nonnull. We do nothing if n is 0. */
static inline void *memcpy_safe(void *dst, const void *src, size_t n) {
if (n == 0)
return dst;
@@ -23,7 +23,15 @@ static inline void *memcpy_safe(void *dst, const void *src, size_t n) {
return memcpy(dst, src, n);
}
-/* Normal memcmp requires s1 and s2 to be nonnull. We do nothing if n is 0. */
+/* Normal mempcpy() requires src to be nonnull. We do nothing if n is 0. */
+static inline void *mempcpy_safe(void *dst, const void *src, size_t n) {
+ if (n == 0)
+ return dst;
+ assert(src);
+ return mempcpy(dst, src, n);
+}
+
+/* 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) {
if (n == 0)
return 0;