[PATCH] compile warning-free also with upcoming gcc-4.4

Jim Meyering meyering at redhat.com
Sun Feb 8 09:53:01 UTC 2009


* libparted/fs/fat/fat.c (_gen_new_serial_number): Use a union
rather than a warning-provoking cast.  Avoids this gcc warning:
"dereferencing type-punned pointer will break strict-aliasing rules"
---
 libparted/fs/fat/fat.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/libparted/fs/fat/fat.c b/libparted/fs/fat/fat.c
index c5fe967..242162f 100644
--- a/libparted/fs/fat/fat.c
+++ b/libparted/fs/fat/fat.c
@@ -1,6 +1,6 @@
 /*
     libparted
-    Copyright (C) 1998, 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1998-2001, 2007-2009 Free Software Foundation, Inc.

     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -265,12 +265,15 @@ fat_root_dir_clear (PedFileSystem* fs)
  * with /dev/random) number.  Unfortunately, we can only use 4 bytes of it
  */
 static uint32_t
-_gen_new_serial_number ()
+_gen_new_serial_number (void)
 {
-	uuid_t		uuid;
+	union {
+		uuid_t uuid;
+		uint32_t i;
+	} uu32;

-	uuid_generate (uuid);
-	return * (uint32_t*) &uuid [0];
+	uuid_generate (uu32.uuid);
+	return uu32.i;
 }

 PedFileSystem*
--
1.6.1.2.549.g547ef



More information about the parted-devel mailing list