mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-28 14:38:21 +01:00
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:
parent
4dfa86b29c
commit
ac591cf22e
@ -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 ReadJPEG(FILE* in_file, WebPPicture* const pic, Metadata* const metadata) {
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
int stride, width, height;
|
int stride, width, height;
|
||||||
struct jpeg_decompress_struct dinfo;
|
volatile struct jpeg_decompress_struct dinfo;
|
||||||
struct my_error_mgr jerr;
|
struct my_error_mgr jerr;
|
||||||
uint8_t* rgb = NULL;
|
volatile uint8_t* rgb = NULL;
|
||||||
JSAMPROW buffer[1];
|
JSAMPROW buffer[1];
|
||||||
|
|
||||||
|
memset((j_decompress_ptr)&dinfo, 0, sizeof(dinfo)); // for setjmp sanity
|
||||||
dinfo.err = jpeg_std_error(&jerr.pub);
|
dinfo.err = jpeg_std_error(&jerr.pub);
|
||||||
jerr.pub.error_exit = my_error_exit;
|
jerr.pub.error_exit = my_error_exit;
|
||||||
|
|
||||||
if (setjmp(jerr.setjmp_buffer)) {
|
if (setjmp(jerr.setjmp_buffer)) {
|
||||||
Error:
|
Error:
|
||||||
MetadataFree(metadata);
|
MetadataFree(metadata);
|
||||||
jpeg_destroy_decompress(&dinfo);
|
jpeg_destroy_decompress((j_decompress_ptr)&dinfo);
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_create_decompress(&dinfo);
|
jpeg_create_decompress((j_decompress_ptr)&dinfo);
|
||||||
jpeg_stdio_src(&dinfo, in_file);
|
jpeg_stdio_src((j_decompress_ptr)&dinfo, in_file);
|
||||||
if (metadata != NULL) SaveMetadataMarkers(&dinfo);
|
if (metadata != NULL) SaveMetadataMarkers((j_decompress_ptr)&dinfo);
|
||||||
jpeg_read_header(&dinfo, TRUE);
|
jpeg_read_header((j_decompress_ptr)&dinfo, TRUE);
|
||||||
|
|
||||||
dinfo.out_color_space = JCS_RGB;
|
dinfo.out_color_space = JCS_RGB;
|
||||||
dinfo.do_fancy_upsampling = TRUE;
|
dinfo.do_fancy_upsampling = TRUE;
|
||||||
|
|
||||||
jpeg_start_decompress(&dinfo);
|
jpeg_start_decompress((j_decompress_ptr)&dinfo);
|
||||||
|
|
||||||
if (dinfo.output_components != 3) {
|
if (dinfo.output_components != 3) {
|
||||||
goto Error;
|
goto Error;
|
||||||
@ -251,31 +252,31 @@ int ReadJPEG(FILE* in_file, WebPPicture* const pic, Metadata* const metadata) {
|
|||||||
buffer[0] = (JSAMPLE*)rgb;
|
buffer[0] = (JSAMPLE*)rgb;
|
||||||
|
|
||||||
while (dinfo.output_scanline < dinfo.output_height) {
|
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;
|
goto End;
|
||||||
}
|
}
|
||||||
buffer[0] += stride;
|
buffer[0] += stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metadata != NULL) {
|
if (metadata != NULL) {
|
||||||
ok = ExtractMetadataFromJPEG(&dinfo, metadata);
|
ok = ExtractMetadataFromJPEG((j_decompress_ptr)&dinfo, metadata);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
fprintf(stderr, "Error extracting JPEG metadata!\n");
|
fprintf(stderr, "Error extracting JPEG metadata!\n");
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_decompress(&dinfo);
|
jpeg_finish_decompress((j_decompress_ptr)&dinfo);
|
||||||
jpeg_destroy_decompress(&dinfo);
|
jpeg_destroy_decompress((j_decompress_ptr)&dinfo);
|
||||||
|
|
||||||
// WebP conversion.
|
// WebP conversion.
|
||||||
pic->width = width;
|
pic->width = width;
|
||||||
pic->height = height;
|
pic->height = height;
|
||||||
ok = WebPPictureImportRGB(pic, rgb, stride);
|
ok = WebPPictureImportRGB(pic, (const uint8_t*)rgb, stride);
|
||||||
if (!ok) goto Error;
|
if (!ok) goto Error;
|
||||||
|
|
||||||
End:
|
End:
|
||||||
free(rgb);
|
free((void*)rgb);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
#else // !WEBP_HAVE_JPEG
|
#else // !WEBP_HAVE_JPEG
|
||||||
|
@ -190,9 +190,9 @@ static int ExtractMetadataFromPNG(png_structp png,
|
|||||||
|
|
||||||
int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
||||||
Metadata* const metadata) {
|
Metadata* const metadata) {
|
||||||
png_structp png;
|
volatile png_structp png;
|
||||||
png_infop info = NULL;
|
volatile png_infop info = NULL;
|
||||||
png_infop end_info = NULL;
|
volatile png_infop end_info = NULL;
|
||||||
int color_type, bit_depth, interlaced;
|
int color_type, bit_depth, interlaced;
|
||||||
int has_alpha;
|
int has_alpha;
|
||||||
int num_passes;
|
int num_passes;
|
||||||
@ -200,7 +200,7 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
|||||||
int ok = 0;
|
int ok = 0;
|
||||||
png_uint_32 width, height, y;
|
png_uint_32 width, height, y;
|
||||||
int stride;
|
int stride;
|
||||||
uint8_t* rgb = NULL;
|
volatile uint8_t* rgb = NULL;
|
||||||
|
|
||||||
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
|
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
|
||||||
if (png == NULL) {
|
if (png == NULL) {
|
||||||
@ -211,7 +211,6 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
|||||||
if (setjmp(png_jmpbuf(png))) {
|
if (setjmp(png_jmpbuf(png))) {
|
||||||
Error:
|
Error:
|
||||||
MetadataFree(metadata);
|
MetadataFree(metadata);
|
||||||
png_destroy_read_struct(&png, &info, &end_info);
|
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +227,9 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
|||||||
|
|
||||||
png_set_strip_16(png);
|
png_set_strip_16(png);
|
||||||
png_set_packing(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 ||
|
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
|
||||||
if (bit_depth < 8) {
|
if (bit_depth < 8) {
|
||||||
@ -255,7 +256,7 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
|||||||
if (rgb == NULL) goto Error;
|
if (rgb == NULL) goto Error;
|
||||||
for (p = 0; p < num_passes; ++p) {
|
for (p = 0; p < num_passes; ++p) {
|
||||||
for (y = 0; y < height; ++y) {
|
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);
|
png_read_rows(png, &row, NULL, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,20 +268,22 @@ int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
|
|||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_destroy_read_struct(&png, &info, &end_info);
|
|
||||||
|
|
||||||
pic->width = width;
|
pic->width = width;
|
||||||
pic->height = height;
|
pic->height = height;
|
||||||
pic->use_argb = 1;
|
pic->use_argb = 1;
|
||||||
ok = has_alpha ? WebPPictureImportRGBA(pic, rgb, stride)
|
ok = has_alpha ? WebPPictureImportRGBA(pic, (const uint8_t*)rgb, stride)
|
||||||
: WebPPictureImportRGB(pic, rgb, stride);
|
: WebPPictureImportRGB(pic, (const uint8_t*)rgb, stride);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
End:
|
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;
|
return ok;
|
||||||
}
|
}
|
||||||
#else // !WEBP_HAVE_PNG
|
#else // !WEBP_HAVE_PNG
|
||||||
|
Loading…
Reference in New Issue
Block a user