]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: fix warning in adfs superblock probe
authorDave Chinner <david@fromorbit.com>
Mon, 18 Jan 2010 00:09:17 +0000 (11:09 +1100)
committerDave Chinner <david@fromorbit.com>
Mon, 18 Jan 2010 00:09:17 +0000 (11:09 +1100)
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 <david@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libdisk/fstype.c

index f84b4e4eb0ceae87ab4be742b96e31b1eff6a2c5..548f29735a6b01124c36bcb8d997ec154fad0c00 100644 (file)
@@ -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";