<http://webkit.org/b/58172> Fix -Wcast-align warning in WebBasePluginPackage.mm
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2011 19:30:34 +0000 (19:30 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2011 19:30:34 +0000 (19:30 +0000)
Reviewed by Anders Carlsson.

Fixes the following warning with -Wcast-align enabled:

    Source/WebKit/mac/Plugins/WebBasePluginPackage.mm:402:21:{402:21-402:93}{402:39-402:93}: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'struct fat_arch *' increases required alignment from 1 to 4 [-Werror,-Wcast-align,3]
                 archs = (struct fat_arch*)((uint8_t*)rawData.data() + sizeof(struct fat_header));
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Plugins/WebBasePluginPackage.mm:
(-[WebBasePluginPackage isNativeLibraryData:]): Added
COMPILE_ASSERT() to make sure our pointer math is valid.
Removed cast to (uint8_t*) and divide sizeof(struct fat_header)
by sizeof(uint32_t) to fix the pointer math.  Replaced C-style
casts with reinterpret_cast.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83755 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Plugins/WebBasePluginPackage.mm

index 15925a8185708c9a039da3130c1188f5548ae362..dad50b3577e332536a97b596cbbe75435a466480 100644 (file)
@@ -1,3 +1,22 @@
+2011-04-13  David Kilzer  <ddkilzer@apple.com>
+
+        <http://webkit.org/b/58172> Fix -Wcast-align warning in WebBasePluginPackage.mm
+
+        Reviewed by Anders Carlsson.
+
+        Fixes the following warning with -Wcast-align enabled:
+
+            Source/WebKit/mac/Plugins/WebBasePluginPackage.mm:402:21:{402:21-402:93}{402:39-402:93}: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'struct fat_arch *' increases required alignment from 1 to 4 [-Werror,-Wcast-align,3]
+                         archs = (struct fat_arch*)((uint8_t*)rawData.data() + sizeof(struct fat_header));
+                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+        * Plugins/WebBasePluginPackage.mm:
+        (-[WebBasePluginPackage isNativeLibraryData:]): Added
+        COMPILE_ASSERT() to make sure our pointer math is valid.
+        Removed cast to (uint8_t*) and divide sizeof(struct fat_header)
+        by sizeof(uint32_t) to fix the pointer math.  Replaced C-style
+        casts with reinterpret_cast.
+
 2011-04-12  Enrica Casucci  <enrica@apple.com>
 
         Reviewed by Alexey Proskuryakov.
index 3fb86cb932d915505a0df82e86a179317fb99fd3..128834e790db12bb76244d2da1e8fbb1f50e8cf4 100644 (file)
@@ -403,8 +403,9 @@ static inline void swapIntsInHeader(uint32_t* rawData, size_t length)
             if (magic == FAT_CIGAM)
                 swapIntsInHeader(rawData.data(), rawData.size());
             
-            archs = (struct fat_arch*)((uint8_t*)rawData.data() + sizeof(struct fat_header));            
-            numArchs = ((struct fat_header *)rawData.data())->nfat_arch;
+            COMPILE_ASSERT(sizeof(struct fat_header) % sizeof(uint32_t) == 0, struct_fat_header_must_be_integral_size_of_uint32_t);
+            archs = reinterpret_cast<struct fat_arch*>(rawData.data() + sizeof(struct fat_header) / sizeof(uint32_t));
+            numArchs = reinterpret_cast<struct fat_header*>(rawData.data())->nfat_arch;
             
             unsigned maxArchs = (sizeInBytes - sizeof(struct fat_header)) / sizeof(struct fat_arch);
             if (numArchs > maxArchs)