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

Dave Chinner
2010-01-14T10:12:44Z

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>
---
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