From ef609477203013666d186cf913e93f4a8843b6db Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 12 Jul 2008 20:27:36 +1000 Subject: [PATCH] Always initialise a struct super_type to zero --- super-ddf.c | 3 +++ super-intel.c | 2 ++ super0.c | 1 + super1.c | 3 ++- util.c | 6 +++--- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/super-ddf.c b/super-ddf.c index 339db9fa..0c2a0138 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -820,6 +820,7 @@ static struct supertype *match_metadata_desc_ddf(char *arg) return NULL; st = malloc(sizeof(*st)); + memset(st, 0, sizeof(*st)); st->ss = &super_ddf; st->max_devs = 512; st->minor_version = 0; @@ -837,6 +838,7 @@ static struct supertype *match_metadata_desc_ddf_bvd(char *arg) return NULL; st = malloc(sizeof(*st)); + memset(st, 0, sizeof(*st)); st->ss = &super_ddf_bvd; st->max_devs = 512; st->minor_version = 0; @@ -853,6 +855,7 @@ static struct supertype *match_metadata_desc_ddf_svd(char *arg) return NULL; st = malloc(sizeof(*st)); + memset(st, 0, sizeof(*st)); st->ss = &super_ddf_svd; st->max_devs = 512; st->minor_version = 0; diff --git a/super-intel.c b/super-intel.c index 8ca491bd..263e398a 100644 --- a/super-intel.c +++ b/super-intel.c @@ -157,6 +157,7 @@ static struct supertype *match_metadata_desc_imsm(char *arg) return NULL; st = malloc(sizeof(*st)); + memset(st, 0, sizeof(*st)); st->ss = &super_imsm; st->max_devs = IMSM_MAX_DEVICES; st->minor_version = 0; @@ -175,6 +176,7 @@ static struct supertype *match_metadata_desc_imsm_volume(char *arg) return NULL; st = malloc(sizeof(*st)); + memset(st, 0, sizeof(*st)); st->ss = &super_imsm_volume; st->max_devs = IMSM_MAX_DEVICES; st->minor_version = 0; diff --git a/super0.c b/super0.c index b0a625bd..1ca35368 100644 --- a/super0.c +++ b/super0.c @@ -869,6 +869,7 @@ static struct supertype *match_metadata_desc0(char *arg) struct supertype *st = malloc(sizeof(*st)); if (!st) return st; + memset(st, 0, sizeof(*st)); st->ss = &super0; st->info = NULL; st->minor_version = 90; diff --git a/super1.c b/super1.c index 211be823..0fe54e97 100644 --- a/super1.c +++ b/super1.c @@ -1073,8 +1073,8 @@ static int load_super1(struct supertype *st, int fd, char *devname) struct supertype tst; __u64 bestctime = 0; /* guess... choose latest ctime */ + memset(&tst, 0, sizeof(tst)); tst.ss = &super1; - tst.sb = NULL; for (tst.minor_version = 0; tst.minor_version <= 2 ; tst.minor_version++) { switch(load_super1(&tst, fd, devname)) { case 0: super = tst.sb; @@ -1216,6 +1216,7 @@ static struct supertype *match_metadata_desc1(char *arg) struct supertype *st = malloc(sizeof(*st)); if (!st) return st; + memset(st, 0, sizeof(*st)); st->ss = &super1; st->max_devs = 384; st->sb = NULL; diff --git a/util.c b/util.c index 365e66b8..08c6bb0b 100644 --- a/util.c +++ b/util.c @@ -841,6 +841,7 @@ struct supertype *dup_super(struct supertype *orig) st = malloc(sizeof(*st)); if (!st) return st; + memset(st, 0, sizeof(*st)); st->ss = orig->ss; st->max_devs = orig->max_devs; st->minor_version = orig->minor_version; @@ -861,11 +862,10 @@ struct supertype *guess_super(int fd) int i; st = malloc(sizeof(*st)); - memset(st, 0, sizeof(*st)); for (i=0 ; superlist[i]; i++) { int rv; ss = superlist[i]; - st->ss = NULL; + memset(st, 0, sizeof(*st)); rv = ss->load_super(st, fd, NULL); if (rv == 0) { struct mdinfo info; @@ -880,7 +880,7 @@ struct supertype *guess_super(int fd) } if (bestsuper != -1) { int rv; - st->ss = NULL; + memset(st, 0, sizeof(*st)); rv = superlist[bestsuper]->load_super(st, fd, NULL); if (rv == 0) { superlist[bestsuper]->free_super(st); -- 2.39.2