]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/loopdev: more robust initialization
authorKarel Zak <kzak@redhat.com>
Mon, 2 Apr 2012 15:33:34 +0000 (17:33 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 2 Apr 2012 15:33:41 +0000 (17:33 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/loopdev.h
lib/loopdev.c

index 4e68da81fe7658d291081d33d9379cc171643394..906bee03a098249ccbda2f9f8fa8e0773b6b0f04 100644 (file)
@@ -104,6 +104,8 @@ struct loopdev_cxt {
        struct loopdev_iter     iter;   /* scans /sys or /dev for used/free devices */
 };
 
+#define UL_LOOPDEVCXT_EMPTY { .fd = -1, .sysfs = UL_SYSFSCXT_EMPTY }
+
 /*
  * loopdev_cxt.flags
  */
index f917f187c9a52e91f6fff692ebf1ab98a1fb1237..fd3f9bae5d9602dd2e4f96cebd6a02574bb18687 100644 (file)
@@ -144,11 +144,12 @@ int loopcxt_has_device(struct loopdev_cxt *lc)
 int loopcxt_init(struct loopdev_cxt *lc, int flags)
 {
        struct stat st;
+       struct loopdev_cxt dummy = UL_LOOPDEVCXT_EMPTY;
 
        if (!lc)
                return -EINVAL;
 
-       memset(lc, 0, sizeof(*lc));
+       memcpy(lc, &dummy, sizeof(dummy));
        lc->flags = flags;
        loopcxt_set_device(lc, NULL);