From 79e4c6c957aa90d7b7d8e46239ce9af40136b4c8 Mon Sep 17 00:00:00 2001 From: Joe Drago Date: Wed, 11 Mar 2020 13:36:31 -0700 Subject: [PATCH] Preallocate rowPointers in PNG code to avoid -Wclobbered errors --- apps/shared/avifpng.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/shared/avifpng.c b/apps/shared/avifpng.c index b34e361ea..5ce517777 100644 --- a/apps/shared/avifpng.c +++ b/apps/shared/avifpng.c @@ -14,7 +14,7 @@ avifBool avifPNGRead(avifImage * avif, const char * inputFilename, avifPixelForm avifBool readResult = AVIF_FALSE; png_structp png = NULL; png_infop info = NULL; - png_bytep * rowPointers = NULL; + png_bytep * rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * avif->height); avifRGBImage rgb; memset(&rgb, 0, sizeof(avifRGBImage)); @@ -112,7 +112,6 @@ avifBool avifPNGRead(avifImage * avif, const char * inputFilename, avifPixelForm 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]; } @@ -127,9 +126,7 @@ avifBool avifPNGRead(avifImage * avif, const char * inputFilename, avifPixelForm if (png) { png_destroy_read_struct(&png, &info, NULL); } - if (rowPointers) { - free(rowPointers); - } + free(rowPointers); avifRGBImageFreePixels(&rgb); return readResult; } @@ -139,7 +136,7 @@ avifBool avifPNGWrite(avifImage * avif, const char * outputFilename, int request avifBool writeResult = AVIF_FALSE; png_structp png = NULL; png_infop info = NULL; - png_bytep * rowPointers = NULL; + png_bytep * rowPointers = (png_bytep *)malloc(sizeof(png_bytep) * avif->height); avifRGBImage rgb; memset(&rgb, 0, sizeof(avifRGBImage)); @@ -192,7 +189,6 @@ avifBool avifPNGWrite(avifImage * avif, const char * outputFilename, int request 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]; } @@ -208,9 +204,7 @@ avifBool avifPNGWrite(avifImage * avif, const char * outputFilename, int request if (png) { png_destroy_write_struct(&png, &info); } - if (rowPointers) { - free(rowPointers); - } + free(rowPointers); avifRGBImageFreePixels(&rgb); return writeResult; }