Whamcloud - gitweb
e2fsprogs: fix type-punning warnings
authorEric Sandeen <sandeen@redhat.com>
Tue, 14 Dec 2010 19:00:01 +0000 (13:00 -0600)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 16 Dec 2010 22:15:30 +0000 (17:15 -0500)
Flags used during RHEL/Fedora builds lead to a couple type-punning
warnings:

  recovery.c: In function 'do_one_pass':
  recovery.c:539: warning: dereferencing type-punned pointer will break strict-aliasing rules
  ./csum.c: In function 'print_csum':
  ./csum.c:170: warning: dereferencing type-punned pointer will break strict-aliasing rules

The two changes below fix this up.

Note that the csum test binary output changes slightly, but this does
not break any tests.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/recovery.c
lib/ext2fs/Makefile.in
lib/ext2fs/csum.c

index 8e40575..cac9294 100644 (file)
@@ -536,8 +536,10 @@ static int do_one_pass(journal_t *journal,
                                        memcpy(nbh->b_data, obh->b_data,
                                                        journal->j_blocksize);
                                        if (flags & JFS_FLAG_ESCAPE) {
-                                               *((__be32 *)nbh->b_data) =
-                                               cpu_to_be32(JFS_MAGIC_NUMBER);
+                                               journal_header_t *header;
+
+                                               header = (journal_header_t *) &nbh->b_data[0];
+                                               header->h_magic = cpu_to_be32(JFS_MAGIC_NUMBER);
                                        }
 
                                        BUFFER_TRACE(nbh, "marking dirty");
index af1f51f..26b7ed9 100644 (file)
@@ -318,10 +318,11 @@ tst_extents: $(srcdir)/extent.c extent_dbg.c $(DEBUG_OBJS) $(DEPLIBSS) \
                $(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) $(LIBCOM_ERR) \
                -I $(top_srcdir)/debugfs
 
-tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR)
+tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) \
+               $(top_srcdir)/lib/e2p/e2p.h
        $(E) "  LD $@"
        $(Q) $(CC) -o tst_csum $(srcdir)/csum.c -DDEBUG \
-               $(ALL_CFLAGS) $(STATIC_LIBEXT2FS) $(LIBCOM_ERR)
+               $(ALL_CFLAGS) $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(LIBE2P)
 
 mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR)
        $(E) "  LD $@"
index 58ebd23..10f3423 100644 (file)
@@ -143,6 +143,8 @@ errcode_t ext2fs_set_gdt_csum(ext2_filsys fs)
 }
 
 #ifdef DEBUG
+#include "e2p/e2p.h"
+
 void print_csum(const char *msg, ext2_filsys fs, dgrp_t group)
 {
        __u16 crc1, crc2, crc3;
@@ -166,9 +168,9 @@ void print_csum(const char *msg, ext2_filsys fs, dgrp_t group)
        crc2 = ext2fs_crc16(crc1, &swabgroup, sizeof(swabgroup));
        crc3 = ext2fs_crc16(crc2, desc,
                            offsetof(struct ext2_group_desc, bg_checksum));
-       printf("%s: UUID %016Lx%016Lx(%04x), grp %u(%04x): %04x=%04x\n",
-              msg, *(long long *)&sb->s_uuid, *(long long *)&sb->s_uuid[8],
-              crc1, group, crc2, crc3, ext2fs_group_desc_csum(fs, group));
+       printf("%s: UUID %s(%04x), grp %u(%04x): %04x=%04x\n",
+              msg, e2p_uuid2str(sb->s_uuid), crc1, group, crc2,crc3,
+              ext2fs_group_desc_csum(fs, group));
 }
 
 unsigned char sb_uuid[16] = { 0x4f, 0x25, 0xe8, 0xcf, 0xe7, 0x97, 0x48, 0x23,