]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: add assertions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Aug 2025 07:49:32 +0000 (16:49 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 17 Sep 2025 12:18:54 +0000 (14:18 +0200)
To silence coverity.

Closes CID#1620098.

src/boot/util.h

index 98e9ae576eee1be9cb698231debd250701a231c2..e7a3ba03033cc59432eee23ff9a29966ef36949e 100644 (file)
@@ -46,10 +46,16 @@ static inline void *xmalloc_multiply(size_t n, size_t size) {
 /* Use malloc attribute as this never returns p like userspace realloc. */
 _malloc_ _alloc_(3) _returns_nonnull_ _warn_unused_result_
 static inline void *xrealloc(void *p, size_t old_size, size_t new_size) {
+        assert(p || old_size == 0);
+
         void *t = xmalloc(new_size);
-        new_size = MIN(old_size, new_size);
-        if (new_size > 0)
-                memcpy(t, p, new_size);
+
+        size_t size = MIN(old_size, new_size);
+        if (size > 0) {
+                assert(p);
+                memcpy(t, p, size);
+        }
+
         free(p);
         return t;
 }