fix for gcc-4.9 warnings about longjmp + local variables

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
This commit is contained in:
skal 2014-05-28 11:00:59 +02:00 committed by Gerrit Code Review
parent 4dfa86b29c
commit ac591cf22e
2 changed files with 30 additions and 26 deletions

View File

@ -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

View File

@ -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