Revert "Preallocate rowPointers in PNG code to avoid -Wclobbered errors" This reverts commit 79e4c6c957aa90d7b7d8e46239ce9af40136b4c8.
diff --git a/apps/shared/avifpng.c b/apps/shared/avifpng.c index 5ce5177..b34e361 100644 --- a/apps/shared/avifpng.c +++ b/apps/shared/avifpng.c
@@ -14,7 +14,7 @@ avifBool readResult = AVIF_FALSE; png_structp png = NULL; png_infop info = NULL; - png_bytep * rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * avif->height); + png_bytep * rowPointers = NULL; avifRGBImage rgb; memset(&rgb, 0, sizeof(avifRGBImage)); @@ -112,6 +112,7 @@ avifRGBImageSetDefaults(&rgb, avif); rgb.depth = imgBitDepth; avifRGBImageAllocatePixels(&rgb); + rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * rgb.height); for (uint32_t y = 0; y < rgb.height; ++y) { rowPointers[y] = &rgb.pixels[y * rgb.rowBytes]; } @@ -126,7 +127,9 @@ if (png) { png_destroy_read_struct(&png, &info, NULL); } - free(rowPointers); + if (rowPointers) { + free(rowPointers); + } avifRGBImageFreePixels(&rgb); return readResult; } @@ -136,7 +139,7 @@ avifBool writeResult = AVIF_FALSE; png_structp png = NULL; png_infop info = NULL; - png_bytep * rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * avif->height); + png_bytep * rowPointers = NULL; avifRGBImage rgb; memset(&rgb, 0, sizeof(avifRGBImage)); @@ -189,6 +192,7 @@ rgb.depth = rgbDepth; avifRGBImageAllocatePixels(&rgb); avifImageYUVToRGB(avif, &rgb); + rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * rgb.height); for (uint32_t y = 0; y < rgb.height; ++y) { rowPointers[y] = &rgb.pixels[y * rgb.rowBytes]; } @@ -204,7 +208,9 @@ if (png) { png_destroy_write_struct(&png, &info); } - free(rowPointers); + if (rowPointers) { + free(rowPointers); + } avifRGBImageFreePixels(&rgb); return writeResult; }