issue #931: dynamically allocate array(row_pointers) in CCImage::_initWithPngData.

This commit is contained in:
James Chen 2012-04-26 18:17:57 +08:00
parent 1b2bba06c5
commit 2bffd3a565
1 changed files with 11 additions and 7 deletions

View File

@ -290,7 +290,9 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen)
// read png data
// m_nBitsPerComponent will always be 8
m_pData = new unsigned char[m_nWidth * m_nHeight * channels];
png_bytep row_pointers[m_nHeight];
png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep)*m_nHeight);
if (row_pointers)
{
const unsigned int stride = m_nWidth * channels;
for (size_t i = 0; i < m_nHeight; ++i)
{
@ -298,8 +300,10 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen)
row_pointers[i] = (png_bytep)m_pData + q;
}
png_read_image(png_ptr, row_pointers);
free(row_pointers);
bRet = true;
}
} while (0);
out: