mirror of https://github.com/axmolengine/axmol.git
Avoid crash on large file download. (#17735)
Downloading large file to memory could cause stack overflow and crash, because old code created buffer `char buf[buflen];` in stack. New code creates buffer in heap.
This commit is contained in:
parent
e45cb88ead
commit
07bb0b2393
|
@ -414,9 +414,9 @@ namespace cocos2d { namespace network {
|
|||
std::string errorString;
|
||||
|
||||
const int64_t buflen = [wrapper totalBytesReceived];
|
||||
char buf[buflen];
|
||||
std::vector<unsigned char> data((size_t)buflen);
|
||||
char* buf = (char*)data.data();
|
||||
[wrapper transferDataToBuffer:buf lengthOfBuffer:buflen];
|
||||
std::vector<unsigned char> data(buf, buf + buflen);
|
||||
|
||||
_outer->onTaskFinish(*[wrapper get],
|
||||
cocos2d::network::DownloadTask::ERROR_NO_ERROR,
|
||||
|
|
Loading…
Reference in New Issue