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,16 +290,20 @@ 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];
const unsigned int stride = m_nWidth * channels;
for (size_t i = 0; i < m_nHeight; ++i)
png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep)*m_nHeight);
if (row_pointers)
{
png_uint_32 q = i * stride;
row_pointers[i] = (png_bytep)m_pData + q;
const unsigned int stride = m_nWidth * channels;
for (size_t i = 0; i < m_nHeight; ++i)
{
png_uint_32 q = i * stride;
row_pointers[i] = (png_bytep)m_pData + q;
}
png_read_image(png_ptr, row_pointers);
free(row_pointers);
bRet = true;
}
png_read_image(png_ptr, row_pointers);
bRet = true;
} while (0);
out: