Changeset 74172 in webkit


Ignore:
Timestamp:
Dec 15, 2010 8:35:13 PM (13 years ago)
Author:
cwzwarich@webkit.org
Message:

Reviewed by Darin Adler.

Clang -Wcast-align gives an error in WebBasePluginPackage.mm
https://bugs.webkit.org/show_bug.cgi?id=51144

Fix an alignment issue. OSSwapInt32 takes data that is 32-bit aligned on ARM, but
we were calling it on a byte array 32 bits at a time. While this is okay in practice,
since TCMalloc won't give us a non-32-bit aligned block array of bytes and Vector's
inline storage is at the beginning of the Vector, it is still better to fix this
and silence the warning.

  • Plugins/WebBasePluginPackage.mm:

(swapIntsInHeader):
(-[WebBasePluginPackage isNativeLibraryData:]):

Location:
trunk/WebKit/mac
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/mac/ChangeLog

    r74065 r74172  
     12010-12-15  Cameron Zwarich  <zwarich@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Clang -Wcast-align gives an error in WebBasePluginPackage.mm
     6        https://bugs.webkit.org/show_bug.cgi?id=51144
     7
     8        Fix an alignment issue. OSSwapInt32 takes data that is 32-bit aligned on ARM, but
     9        we were calling it on a byte array 32 bits at a time. While this is okay in practice,
     10        since TCMalloc won't give us a non-32-bit aligned block array of bytes and Vector's
     11        inline storage is at the beginning of the Vector, it is still better to fix this
     12        and silence the warning.
     13
     14        * Plugins/WebBasePluginPackage.mm:
     15        (swapIntsInHeader):
     16        (-[WebBasePluginPackage isNativeLibraryData:]):
     17
    1182010-12-14  Mark Rowe  <mrowe@apple.com>
    219
  • trunk/WebKit/mac/Plugins/WebBasePluginPackage.mm

    r65021 r74172  
    344344}
    345345
    346 static inline void swapIntsInHeader(uint8_t* bytes, unsigned length)
    347 {
    348     for (unsigned i = 0; i < length; i += 4)
    349         *(uint32_t*)(bytes + i) = OSSwapInt32(*(uint32_t *)(bytes + i));
     346static inline void swapIntsInHeader(uint32_t* rawData, size_t length)
     347{
     348    for (size_t i = 0; i < length; ++i)
     349        rawData[i] = OSSwapInt32(rawData[i]);
    350350}
    351351
    352352- (BOOL)isNativeLibraryData:(NSData *)data
    353353{
    354     Vector<uint8_t, 512> bytes([data length]);
    355     memcpy(bytes.data(), [data bytes], bytes.size());
     354    NSUInteger sizeInBytes = [data length];
     355    Vector<uint32_t, 128> rawData((sizeInBytes - 1) / 4 + 1);
     356    memcpy(rawData.data(), [data bytes], sizeInBytes);
    356357   
    357358    unsigned numArchs = 0;
     
    359360    struct fat_arch* archs = 0;
    360361       
    361     if (bytes.size() >= sizeof(struct mach_header_64)) {
    362         uint32_t magic = *reinterpret_cast<uint32_t*>(bytes.data());
     362    if (sizeInBytes >= sizeof(struct mach_header_64)) {
     363        uint32_t magic = *rawData.data();
    363364       
    364365        if (magic == MH_MAGIC || magic == MH_CIGAM) {
    365366            // We have a 32-bit thin binary
    366             struct mach_header* header = (struct mach_header*)bytes.data();
     367            struct mach_header* header = (struct mach_header*)rawData.data();
    367368
    368369            // Check if we need to swap the bytes
    369370            if (magic == MH_CIGAM)
    370                 swapIntsInHeader(bytes.data(), bytes.size());
     371                swapIntsInHeader(rawData.data(), rawData.size());
    371372   
    372373            singleArch.cputype = header->cputype;
     
    377378        } else if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) {
    378379            // We have a 64-bit thin binary
    379             struct mach_header_64* header = (struct mach_header_64*)bytes.data();
     380            struct mach_header_64* header = (struct mach_header_64*)rawData.data();
    380381
    381382            // Check if we need to swap the bytes
    382383            if (magic == MH_CIGAM_64)
    383                 swapIntsInHeader(bytes.data(), bytes.size());
     384                swapIntsInHeader(rawData.data(), rawData.size());
    384385           
    385386            singleArch.cputype = header->cputype;
     
    393394            // Check if we need to swap the bytes
    394395            if (magic == FAT_CIGAM)
    395                 swapIntsInHeader(bytes.data(), bytes.size());
     396                swapIntsInHeader(rawData.data(), rawData.size());
    396397           
    397             archs = (struct fat_arch*)(bytes.data() + sizeof(struct fat_header));           
    398             numArchs = ((struct fat_header *)bytes.data())->nfat_arch;
     398            archs = (struct fat_arch*)(rawData.data() + sizeof(struct fat_header));           
     399            numArchs = ((struct fat_header *)rawData.data())->nfat_arch;
    399400           
    400             unsigned maxArchs = (bytes.size() - sizeof(struct fat_header)) / sizeof(struct fat_arch);
     401            unsigned maxArchs = (sizeInBytes - sizeof(struct fat_header)) / sizeof(struct fat_arch);
    401402            if (numArchs > maxArchs)
    402403                numArchs = maxArchs;
Note: See TracChangeset for help on using the changeset viewer.