Commit e440e722 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

compext/Png.c: simplify srcBuf allocation

parent d4882419
...@@ -481,47 +481,23 @@ char *PngCompressData(XImage *image, int *compressed_size) ...@@ -481,47 +481,23 @@ char *PngCompressData(XImage *image, int *compressed_size)
return NULL; return NULL;
} }
int count;
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)
{ {
srcBuf = (CARD8 *) malloc(w * sizeof(CARD8)); count = w;
if (srcBuf == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
(int) (w * sizeof(CARD8)));
#endif
free(image_index);
return NULL;
}
/*
* TODO: Be sure the padded bytes are cleaned.
* It would be better to set to zero the bytes
* that are not aligned to the word boundary
* at the end of the procedure.
*/
memset(srcBuf, 0, w * sizeof(CARD8));
} }
else else
{ {
srcBuf = (CARD8 *) malloc(w * 3 * sizeof(CARD8)); count = 3 * w;
/*
* TODO: See above.
*/
memset(srcBuf, 0, w * 3 * sizeof(CARD8));
} }
srcBuf = (CARD8 *) calloc(count, sizeof(CARD8));
if (srcBuf == NULL) if (srcBuf == NULL)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n", fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
w * 3); (int) (count * sizeof(CARD8)));
#endif #endif
free(pngCompBuf); free(pngCompBuf);
...@@ -530,6 +506,13 @@ char *PngCompressData(XImage *image, int *compressed_size) ...@@ -530,6 +506,13 @@ char *PngCompressData(XImage *image, int *compressed_size)
return NULL; return NULL;
} }
/*
* TODO: Be sure the padded bytes are cleaned.
* It would be better to set to zero the bytes
* that are not aligned to the word boundary
* at the end of the procedure.
*/
for (dy = 0; dy < h; dy++) for (dy = 0; dy < h; dy++)
{ {
if (color_type == PNG_COLOR_TYPE_RGB) if (color_type == PNG_COLOR_TYPE_RGB)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment