From ac591cf22e0649eb7bb46985d8314483d451e6f8 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 May 2014 11:00:59 +0200 Subject: [PATCH] fix for gcc-4.9 warnings about longjmp + local variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Needed to add 'volatile' and some casts. Relevant excerpt from the 'man longjmp': =============== The values of automatic variables are unspecified after a call to longjmp() if they meet all the following criteria: · they are local to the function that made the corresponding setjmp(3) call; · their values are changed between the calls to setjmp(3) and longjmp(); and · they are not declared as volatile. =============== Change-Id: Ic72dc92669513a820369ca52a038afa9ec88091f --- examples/jpegdec.c | 29 +++++++++++++++-------------- examples/pngdec.c | 27 +++++++++++++++------------ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/examples/jpegdec.c b/examples/jpegdec.c index 227d42fc..ec227e35 100644 --- a/examples/jpegdec.c +++ b/examples/jpegdec.c @@ -211,30 +211,31 @@ static void my_error_exit(j_common_ptr dinfo) { int ReadJPEG(FILE* in_file, WebPPicture* const pic, Metadata* const metadata) { int ok = 0; int stride, width, height; - struct jpeg_decompress_struct dinfo; + volatile struct jpeg_decompress_struct dinfo; struct my_error_mgr jerr; - uint8_t* rgb = NULL; + volatile uint8_t* rgb = NULL; JSAMPROW buffer[1]; + memset((j_decompress_ptr)&dinfo, 0, sizeof(dinfo)); // for setjmp sanity dinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { Error: MetadataFree(metadata); - jpeg_destroy_decompress(&dinfo); + jpeg_destroy_decompress((j_decompress_ptr)&dinfo); goto End; } - jpeg_create_decompress(&dinfo); - jpeg_stdio_src(&dinfo, in_file); - if (metadata != NULL) SaveMetadataMarkers(&dinfo); - jpeg_read_header(&dinfo, TRUE); + jpeg_create_decompress((j_decompress_ptr)&dinfo); + jpeg_stdio_src((j_decompress_ptr)&dinfo, in_file); + if (metadata != NULL) SaveMetadataMarkers((j_decompress_ptr)&dinfo); + jpeg_read_header((j_decompress_ptr)&dinfo, TRUE); dinfo.out_color_space = JCS_RGB; dinfo.do_fancy_upsampling = TRUE; - jpeg_start_decompress(&dinfo); + jpeg_start_decompress((j_decompress_ptr)&dinfo); if (dinfo.output_components != 3) { goto Error; @@ -251,31 +252,31 @@ int ReadJPEG(FILE* in_file, WebPPicture* const pic, Metadata* const metadata) { buffer[0] = (JSAMPLE*)rgb; while (dinfo.output_scanline < dinfo.output_height) { - if (jpeg_read_scanlines(&dinfo, buffer, 1) != 1) { + if (jpeg_read_scanlines((j_decompress_ptr)&dinfo, buffer, 1) != 1) { goto End; } buffer[0] += stride; } if (metadata != NULL) { - ok = ExtractMetadataFromJPEG(&dinfo, metadata); + ok = ExtractMetadataFromJPEG((j_decompress_ptr)&dinfo, metadata); if (!ok) { fprintf(stderr, "Error extracting JPEG metadata!\n"); goto Error; } } - jpeg_finish_decompress(&dinfo); - jpeg_destroy_decompress(&dinfo); + jpeg_finish_decompress((j_decompress_ptr)&dinfo); + jpeg_destroy_decompress((j_decompress_ptr)&dinfo); // WebP conversion. pic->width = width; pic->height = height; - ok = WebPPictureImportRGB(pic, rgb, stride); + ok = WebPPictureImportRGB(pic, (const uint8_t*)rgb, stride); if (!ok) goto Error; End: - free(rgb); + free((void*)rgb); return ok; } #else // !WEBP_HAVE_JPEG diff --git a/examples/pngdec.c b/examples/pngdec.c index 332f6bbd..371ce2a9 100644 --- a/examples/pngdec.c +++ b/examples/pngdec.c @@ -190,9 +190,9 @@ static int ExtractMetadataFromPNG(png_structp png, int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha, Metadata* const metadata) { - png_structp png; - png_infop info = NULL; - png_infop end_info = NULL; + volatile png_structp png; + volatile png_infop info = NULL; + volatile png_infop end_info = NULL; int color_type, bit_depth, interlaced; int has_alpha; int num_passes; @@ -200,7 +200,7 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha, int ok = 0; png_uint_32 width, height, y; int stride; - uint8_t* rgb = NULL; + volatile uint8_t* rgb = NULL; png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); if (png == NULL) { @@ -211,7 +211,6 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha, if (setjmp(png_jmpbuf(png))) { Error: MetadataFree(metadata); - png_destroy_read_struct(&png, &info, &end_info); goto End; } @@ -228,7 +227,9 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha, png_set_strip_16(png); png_set_packing(png); - if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png); + if (color_type == PNG_COLOR_TYPE_PALETTE) { + png_set_palette_to_rgb(png); + } if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { if (bit_depth < 8) { @@ -255,7 +256,7 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha, if (rgb == NULL) goto Error; for (p = 0; p < num_passes; ++p) { for (y = 0; y < height; ++y) { - png_bytep row = rgb + y * stride; + png_bytep row = (png_bytep)(rgb + y * stride); png_read_rows(png, &row, NULL, 1); } } @@ -267,20 +268,22 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha, goto Error; } - png_destroy_read_struct(&png, &info, &end_info); - pic->width = width; pic->height = height; pic->use_argb = 1; - ok = has_alpha ? WebPPictureImportRGBA(pic, rgb, stride) - : WebPPictureImportRGB(pic, rgb, stride); + ok = has_alpha ? WebPPictureImportRGBA(pic, (const uint8_t*)rgb, stride) + : WebPPictureImportRGB(pic, (const uint8_t*)rgb, stride); if (!ok) { goto Error; } End: - free(rgb); + if (png != NULL) { + png_destroy_read_struct((png_structpp)&png, + (png_infopp)&info, (png_infopp)&end_info); + } + free((void*)rgb); return ok; } #else // !WEBP_HAVE_PNG