Skip to content

Commit

Permalink
Preallocate rowPointers in PNG code to avoid -Wclobbered errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Drago committed Mar 11, 2020
1 parent e5003b1 commit 79e4c6c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions apps/shared/avifpng.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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];
}
Expand All @@ -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;
}
Expand All @@ -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));
Expand Down Expand Up @@ -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];
}
Expand All @@ -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;
}

0 comments on commit 79e4c6c

Please sign in to comment.