From: Dave Chinner Date: Mon, 18 Jan 2010 00:09:17 +0000 (+1100) Subject: xfsprogs: fix warning in adfs superblock probe X-Git-Tag: v3.1.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69093797545e9005745f8cb9ee817e635407c63f;p=thirdparty%2Fxfsprogs-dev.git xfsprogs: fix warning in adfs superblock probe The probe gets an array subscript warning because gcc is not smart enough to realise that a structure made up of multiple byte arrays in it can be referenced as a flat buffer and it is valid to access bytes beyond the first array in the structure.... Fix it by passing the adfs superblock in and using the internal checksum array to get the checksum value. Signed-off-by: Dave Chinner Reviewed-by: Christoph Hellwig --- diff --git a/libdisk/fstype.c b/libdisk/fstype.c index f84b4e4eb..548f29735 100644 --- a/libdisk/fstype.c +++ b/libdisk/fstype.c @@ -142,16 +142,16 @@ may_be_swap(const char *s) { /* rather weak necessary condition */ static int -may_be_adfs(const char *s) { +may_be_adfs(const struct adfs_super_block *sb) { char *p; int sum; - p = (char *) s + 511; + p = (char *)sb->s_checksum; sum = 0; - while(--p != s) + while(--p != (char *)sb) sum = (sum >> 8) + (sum & 0xff) + *p; - return (sum == p[511]); + return (sum & 0xff) == sb->s_checksum[0]; } static int is_reiserfs_magic_string (struct reiserfs_super_block * rs) @@ -304,7 +304,7 @@ fstype(const char *device) { goto io_error; /* only a weak test */ - if (may_be_adfs((char *) &adfssb) + if (may_be_adfs(&adfssb) && (adfsblksize(adfssb) >= 8 && adfsblksize(adfssb) <= 10)) type = "adfs";