Skip to content

Commit

Permalink
Fix potential overflow in Texture::getCachedTextureInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Chen committed Mar 14, 2014
1 parent 6946313 commit d291c58
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cocos/2d/CCTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,9 @@ void TextureCache::waitForQuit()

std::string TextureCache::getCachedTextureInfo() const
{
char buffer[16386];
std::string buffer;
char buftmp[4096];

memset(buffer,0,sizeof(buffer));

unsigned int count = 0;
unsigned int totalBytes = 0;

Expand All @@ -527,13 +525,14 @@ std::string TextureCache::getCachedTextureInfo() const
(long)tex->getPixelsHigh(),
(long)bpp,
(long)bytes / 1024);
strcat(buffer, buftmp);

buffer += buftmp;
}

snprintf(buftmp, sizeof(buftmp)-1, "TextureCache dumpDebugInfo: %ld textures, for %lu KB (%.2f MB)\n", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f));
strcat(buffer, buftmp);
buffer += buftmp;

return std::string(buffer);
return buffer;
}

#if CC_ENABLE_CACHE_TEXTURE_DATA
Expand Down

0 comments on commit d291c58

Please sign in to comment.