* [PATCH] e2fsprogs: fix type-punning warnings
@ 2010-12-14 19:00 Eric Sandeen
  2010-12-15 18:53 ` Edward Shishkin
  2010-12-15 23:09 ` Ted Ts'o
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Sandeen @ 2010-12-14 19:00 UTC (permalink / raw)
  To: ext4 development
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>
---
diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c
index 8e40575..cac9294 100644
--- a/e2fsck/recovery.c
+++ b/e2fsck/recovery.c
@@ -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");
diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
index a71d12c..1024c10 100644
--- a/lib/ext2fs/Makefile.in
+++ b/lib/ext2fs/Makefile.in
@@ -317,7 +317,7 @@ tst_extents: $(srcdir)/extent.c extent_dbg.c $(DEBUG_OBJS) $(DEPLIBSS) \
 tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR)
 	$(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 $@"
diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c
index 58ebd23..2b6b364 100644
--- a/lib/ext2fs/csum.c
+++ b/lib/ext2fs/csum.c
@@ -166,9 +166,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,
^ permalink raw reply related	[flat|nested] 5+ messages in thread
* Re: [PATCH] e2fsprogs: fix type-punning warnings
  2010-12-14 19:00 [PATCH] e2fsprogs: fix type-punning warnings Eric Sandeen
@ 2010-12-15 18:53 ` Edward Shishkin
  2010-12-15 23:09 ` Ted Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Edward Shishkin @ 2010-12-15 18:53 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development
Eric Sandeen wrote:
> 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>
>   
Acked-by: Edward Shishkin <edward@redhat.com>
> ---
>
> diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c
> index 8e40575..cac9294 100644
> --- a/e2fsck/recovery.c
> +++ b/e2fsck/recovery.c
> @@ -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");
> diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
> index a71d12c..1024c10 100644
> --- a/lib/ext2fs/Makefile.in
> +++ b/lib/ext2fs/Makefile.in
> @@ -317,7 +317,7 @@ tst_extents: $(srcdir)/extent.c extent_dbg.c $(DEBUG_OBJS) $(DEPLIBSS) \
>  tst_csum: csum.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR)
>  	$(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 $@"
> diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c
> index 58ebd23..2b6b364 100644
> --- a/lib/ext2fs/csum.c
> +++ b/lib/ext2fs/csum.c
> @@ -166,9 +166,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,
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>   
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [PATCH] e2fsprogs: fix type-punning warnings
  2010-12-14 19:00 [PATCH] e2fsprogs: fix type-punning warnings Eric Sandeen
  2010-12-15 18:53 ` Edward Shishkin
@ 2010-12-15 23:09 ` Ted Ts'o
  2010-12-16 20:39   ` Eric Sandeen
  1 sibling, 1 reply; 5+ messages in thread
From: Ted Ts'o @ 2010-12-15 23:09 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development
On Tue, Dec 14, 2010 at 01:00:01PM -0600, Eric Sandeen wrote:
> 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>
Thanks, applied.  There's also a bone-headed big-endian compile bug
which means I'll be doing an e2fsprogs 1.41.14 shortly.
      	    	    	     	       - Ted
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [PATCH] e2fsprogs: fix type-punning warnings
  2010-12-15 23:09 ` Ted Ts'o
@ 2010-12-16 20:39   ` Eric Sandeen
  2010-12-16 22:15     ` Ted Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Sandeen @ 2010-12-16 20:39 UTC (permalink / raw)
  To: Ted Ts'o; +Cc: ext4 development
On 12/15/2010 05:09 PM, Ted Ts'o wrote:
> On Tue, Dec 14, 2010 at 01:00:01PM -0600, Eric Sandeen wrote:
>> 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>
> 
> Thanks, applied.  There's also a bone-headed big-endian compile bug
> which means I'll be doing an e2fsprogs 1.41.14 shortly.
> 
>       	    	    	     	       - Ted
Hm this may need an include of the e2p.h header as well, if built in
a pristine buildroot...
--- e2fsprogs-1.41.12.orig/lib/ext2fs/csum.c
+++ e2fsprogs-1.41.12/lib/ext2fs/csum.c
@@ -17,6 +17,7 @@
 #include "ext2_fs.h"
 #include "ext2fs.h"
 #include "crc16.h"
+#include "e2p/e2p.h"
 #include <assert.h>
 #ifndef offsetof
Sorry about that,
-Eric
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [PATCH] e2fsprogs: fix type-punning warnings
  2010-12-16 20:39   ` Eric Sandeen
@ 2010-12-16 22:15     ` Ted Ts'o
  0 siblings, 0 replies; 5+ messages in thread
From: Ted Ts'o @ 2010-12-16 22:15 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development
On Thu, Dec 16, 2010 at 02:39:38PM -0600, Eric Sandeen wrote:
> Hm this may need an include of the e2p.h header as well, if built in
> a pristine buildroot...
Actually we only need it if we are building tst_csum (i.e., if #DEBUG
is defined).  So I'll apply it under #ifdef DEBUG, and then add a
dependency for tst_csum in the Makefile.
Thanks for pointing this out.
						- Ted
^ permalink raw reply	[flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-12-16 22:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-14 19:00 [PATCH] e2fsprogs: fix type-punning warnings Eric Sandeen
2010-12-15 18:53 ` Edward Shishkin
2010-12-15 23:09 ` Ted Ts'o
2010-12-16 20:39   ` Eric Sandeen
2010-12-16 22:15     ` Ted Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).