Ticket #12779: 0001-12779-Handle-version-info-in-resource-in-other-endia.patch

File 0001-12779-Handle-version-info-in-resource-in-other-endia.patch, 2.0 KB (added by markh, 8 years ago)
  • src/kits/storage/ResourceFile.cpp

    From 20a72bb2122f4089be00ea9fe918540a63840bbb Mon Sep 17 00:00:00 2001
    From: Mark Hellegers <mark@firedisk.net>
    Date: Sat, 14 May 2016 16:33:38 +0200
    Subject: [PATCH] #12779: Handle version info in resource in other endianness
     than host
    
    ---
     src/kits/storage/ResourceFile.cpp | 23 ++++++++++++++++++++---
     1 file changed, 20 insertions(+), 3 deletions(-)
    
    diff --git a/src/kits/storage/ResourceFile.cpp b/src/kits/storage/ResourceFile.cpp
    index 907ee87..e82d841 100644
    a b const char* kFileTypeNames[] = {  
    6767#define DBG(x)
    6868#define OUT printf
    6969
     70#define B_VERSION_INFO_TYPE 'APPV'
     71
     72static const uint32 kVersionInfoIntCount = 5;
    7073
    7174// #pragma mark - helper functions/classes
    7275
    ResourceFile::ReadResource(ResourceItem& resource, bool force)  
    323326        }
    324327        if (error == B_OK) {
    325328            // convert the data, if necessary
    326             if (!fHostEndianess)
    327                 swap_data(resource.Type(), data, size, B_SWAP_ALWAYS);
     329            if (!fHostEndianess) {
     330                if (resource.Type() == B_VERSION_INFO_TYPE)
     331                    // Version info contains integers that need to be swapped
     332                    swap_data(B_UINT32_TYPE, data,
     333                              kVersionInfoIntCount * sizeof(uint32),
     334                              B_SWAP_ALWAYS);
     335                else
     336                    swap_data(resource.Type(), data, size, B_SWAP_ALWAYS);
     337            }
    328338            resource.SetLoaded(true);
    329339            resource.SetModified(false);
    330340        }
    ResourceFile::_WriteResources(ResourcesContainer& container)  
    12001210                // swap data, if necessary
    12011211                if (!fHostEndianess) {
    12021212                    memcpy(data, itemData, itemSize);
    1203                     swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS);
     1213                    if (item->Type() == B_VERSION_INFO_TYPE)
     1214                        // Version info contains integers
     1215                        // that need to be swapped
     1216                        swap_data(B_UINT32_TYPE, data,
     1217                                  kVersionInfoIntCount * sizeof(uint32),
     1218                                  B_SWAP_ALWAYS);
     1219                    else
     1220                        swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS);
    12041221                    itemData = data;
    12051222                }
    12061223                write_exactly(fFile, itemOffset, itemData, itemSize,