xfs
[Top] [All Lists]

[PATCH 4/9] xfsprogs: fix warning in adfs superblock probe

To: xfs@xxxxxxxxxxx
Subject: [PATCH 4/9] xfsprogs: fix warning in adfs superblock probe
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Thu, 14 Jan 2010 21:09:07 +1100
In-reply-to: <1263463752-5052-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1263463752-5052-1-git-send-email-david@xxxxxxxxxxxxx>
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@xxxxxxxxxxxxx>
---
 libdisk/fstype.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libdisk/fstype.c b/libdisk/fstype.c
index f84b4e4..548f297 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";
-- 
1.6.5

<Prev in Thread] Current Thread [Next in Thread>