Merge pull request #9066 from cpascal/fix_bundlereader

Fixed "warning: bundle reader out of range"
This commit is contained in:
minggo 2014-11-13 18:38:06 +08:00
commit d965062866
1 changed files with 4 additions and 1 deletions

View File

@ -49,13 +49,16 @@ void BundleReader::init(char* buffer, ssize_t length)
ssize_t BundleReader::read(void* ptr, ssize_t size, ssize_t count) ssize_t BundleReader::read(void* ptr, ssize_t size, ssize_t count)
{ {
if (!_buffer || eof()) if (!_buffer || eof())
{
CCLOG("warning: bundle reader out of range");
return 0; return 0;
}
ssize_t validCount; ssize_t validCount;
ssize_t validLength = _length - _position; ssize_t validLength = _length - _position;
ssize_t needLength = size*count; ssize_t needLength = size*count;
char* ptr1 = (char*)ptr; char* ptr1 = (char*)ptr;
if(validLength <= needLength) if(validLength < needLength)
{ {
validCount = validLength/size; validCount = validLength/size;
ssize_t readLength = size*validCount; ssize_t readLength = size*validCount;