[cocos2d-x] Closes #650, don't deep copy data read from file on cocos2d-x 3.12+

This commit is contained in:
badlogic 2016-08-05 10:09:07 +02:00
parent 2b29f9b5b6
commit 819bb4cf0c

View File

@ -82,8 +82,15 @@ char* _spUtil_readFile (const char* path, int* length) {
if (data.isNull()) return 0;
// avoid buffer overflow (int is shorter than ssize_t in certain platforms)
#if COCOS2D_VERSION >= 0x00031200
ssize_t tmpLen;
char *ret = (char*)data.takeBuffer(&tmpLen);
*length = static_cast<int>(tmpLen);
return ret;
#else
*length = static_cast<int>(data.getSize());
char* bytes = MALLOC(char, *length);
memcpy(bytes, data.getBytes(), *length);
return bytes;
#endif
}