summaryrefslogtreecommitdiff
path: root/disk-io.c
diff options
context:
space:
mode:
authorZach Brown <zab@redhat.com>2013-01-17 11:54:47 -0800
committerZach Brown <zab@redhat.com>2013-02-05 16:09:32 -0800
commit52162700bb59663add809a6465ce2769d80b3664 (patch)
tree5cd021a31a6e098ee5e9b9c6b47b02f70f3f147d /disk-io.c
parent2161e1b6f35d1c084fda49b479951219117c86e9 (diff)
btrfs-progs: treat super.magic as an le64
The super block magic is a le64 whose value looks like an unterminated string in memory. The lack of null termination leads to clumsy use of string functions and causes static analysis tools to warn that the string will be unterminated. So let's just treat it as the le64 that it is. Endian wrappers are used on the constant so that they're compiled into run-time constants. Signed-off-by: Zach Brown <zab@redhat.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/disk-io.c b/disk-io.c
index 0bf73f05..d3b8c518 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -932,8 +932,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
return -1;
if (btrfs_super_bytenr(&buf) != sb_bytenr ||
- strncmp((char *)(&buf.magic), BTRFS_MAGIC,
- sizeof(buf.magic)))
+ buf.magic != cpu_to_le64(BTRFS_MAGIC))
return -1;
memcpy(sb, &buf, sizeof(*sb));
@@ -951,8 +950,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
/* if magic is NULL, the device was removed */
if (buf.magic == 0 && i == 0)
return -1;
- if (strncmp((char *)(&buf.magic), BTRFS_MAGIC,
- sizeof(buf.magic)))
+ if (buf.magic != cpu_to_le64(BTRFS_MAGIC))
continue;
if (!fsid_is_initialized) {