I found a bug about CC_SWAP32 macro

ccMacros.h:

original macro
#define CC_SWAP32(i) ((i & 0x000000ff) << 24 | (i & 0x0000ff00 << 8) | (i & 0x00ff0000) >> 8 | (i & 0xff000000) >> 24)

fixed macro
#define CC_SWAP32(i) ((i & 0x000000ff) << 24 | (i & 0x0000ff00) << 8 | (i & 0x00ff0000) >> 8 | (i & 0xff000000) >> 24)

it will lead to failed to uncompress zlib. For example, i = 0x00020034
original : CC_SWAP32(i) = 52
fixed : CC_SWAP32(i) = 020034

btw, i am not sure whether the structure of CCZHeader is correct or not ?
in cocos2d-x 1.0.1-x-0.9.1

    struct CCZHeader {
        unsigned char           sig[4];             // signature. Should be 'CCZ!' 4 bytes
        unsigned short          compression_type;   // should 0
        unsigned char           version;            // should be 2 (although version type==1 is also supported)
        unsigned int            reserved;           // Reserverd for users.
        unsigned int            len;                // size of the uncompressed file
    };

but in cocos2d-1.0.0

    struct CCZHeader {
        uint8_t         sig[4];             // signature. Should be 'CCZ!' 4 bytes
        uint16_t        compression_type;   // should 0
        uint16_t        version;            // should be 2 (although version type==1 is also supported)
        uint32_t        reserved;           // Reserverd for users.
        uint32_t        len;                // size of the uncompressed file
    };

the type of version is different between two versions, and i think the version must is unsigned short.
would you take a look at it ?
best regards.

Thanks for your report.
Yep it’s a bug here. I miss the ‘)’ with a stupid typo. And CCZHeader.version should be unsigned short.
I will fix them soon. Bug #700, #701.

Hi, Tix Lo, One more question, which platform & which test case to reproduce the error of CC_SWAP32?
I have tried iphone/android/win32, but seems the logic hasn’t went into CC_SWAP32. I’m a bit lazy to rewrite the macro into functions for setting break points in it :stuck_out_tongue:

my develop environment :slight_smile:

  1. Xcode 4 + iPhone Simulator 4.3
  2. To use compressed file (xxx.pvr.ccz) to load image resources