From b3edc73afa01b101e8e9773a2298d082bb2c0823 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sun, 21 Nov 2010 14:06:41 -0600 Subject: [PATCH] [devel] Changes to remove gcc warnings (John Bowler) Certain optional gcc warning flags resulted in warnings in libpng code. With these changes only -Wconversion and -Wcast-qual cannot be turned on. Changes are trivial rearrangements of code. -Wconversion is not possible for pngrutil.c (because of the widespread use of += et al on variables smaller than (int) or (unsigned int)) and -Wcast-qual is not possible with pngwio.c and pngwutil.c because the 'write' callback and zlib compression both fail to declare their input buffers with 'const'. --- ANNOUNCE | 9 +++++++++ CHANGES | 9 +++++++++ pngpread.c | 1 + pngread.c | 1 + pngrtran.c | 31 +++++++++++++++++++++++++++++++ pngrutil.c | 5 +++++ pngwtran.c | 3 +++ pngwutil.c | 6 ++++-- 8 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index b98b1963e..4ad0e317b 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -442,6 +442,15 @@ Version 1.5.0beta55 [November 21, 2010] Fixed atomicity of chunk header serialization (Cosmin) Added test for io_state in pngtest.c (Cosmin) Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts. + Changes to remove gcc warnings (John Bowler) + Certain optional gcc warning flags resulted in warnings in libpng code. + With these changes only -Wconversion and -Wcast-qual cannot be turned on. + Changes are trivial rearrangements of code. -Wconversion is not possible + for pngrutil.c (because of the widespread use of += et al on variables + smaller than (int) or (unsigned int)) and -Wcast-qual is not possible + with pngwio.c and pngwutil.c because the 'write' callback and zlib + compression both fail to declare their input buffers with 'const'. + Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index 5d1b44314..a816a9e85 100644 --- a/CHANGES +++ b/CHANGES @@ -3080,6 +3080,15 @@ Version 1.5.0beta55 [November 21, 2010] Fixed atomicity of chunk header serialization (Cosmin) Added test for io_state in pngtest.c (Cosmin) Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts. + Changes to remove gcc warnings (John Bowler) + Certain optional gcc warning flags resulted in warnings in libpng code. + With these changes only -Wconversion and -Wcast-qual cannot be turned on. + Changes are trivial rearrangements of code. -Wconversion is not possible + for pngrutil.c (because of the widespread use of += et al on variables + smaller than (int) or (unsigned int)) and -Wcast-qual is not possible + with pngwio.c and pngwutil.c because the 'write' callback and zlib + compression both fail to declare their input buffers with 'const'. + Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngpread.c b/pngpread.c index 67455c340..c893104b5 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1137,6 +1137,7 @@ png_push_process_row(png_structp png_ptr) break; } + default: case 6: { png_push_have_row(png_ptr, png_ptr->row_buf + 1); diff --git a/pngread.c b/pngread.c index fe180fdfd..30605d1bd 100644 --- a/pngread.c +++ b/pngread.c @@ -618,6 +618,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) } break; + default: case 6: if (!(png_ptr->row_number & 1)) { diff --git a/pngrtran.c b/pngrtran.c index 9cd85dfef..b3425d301 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -719,6 +719,11 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; + break; + + default: + png_error(png_ptr, "invalid error action to rgb_to_gray"); + break; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) #ifdef PNG_READ_EXPAND_SUPPORTED @@ -886,6 +891,8 @@ png_init_read_transformations(png_structp png_ptr) } break; + default: + case 8: case 16: @@ -1088,6 +1095,9 @@ png_init_read_transformations(png_structp png_ptr) gs = png_reciprocal2(png_ptr->background_gamma, png_ptr->screen_gamma); break; + + default: + png_error(png_ptr, "invalid background gamma type"); } png_ptr->background_1.gray = png_gamma_correct(png_ptr, @@ -1725,6 +1735,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row) } break; } + + default: + break; } row_info->bit_depth = 8; row_info->pixel_depth = (png_byte)(8 * row_info->channels); @@ -1785,6 +1798,9 @@ png_do_unshift(png_row_infop row_info, png_bytep row, switch (row_info->bit_depth) { + default: + break; + case 2: { png_bytep bp; @@ -2966,6 +2982,9 @@ png_do_background(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } break; } @@ -3438,6 +3457,9 @@ png_do_background(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } if (row_info->color_type & PNG_COLOR_MASK_ALPHA) @@ -3646,6 +3668,9 @@ png_do_gamma(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } } } @@ -3744,6 +3769,9 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } row_info->bit_depth = 8; row_info->pixel_depth = 8; @@ -3901,6 +3929,9 @@ png_do_expand(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } row_info->bit_depth = 8; diff --git a/pngrutil.c b/pngrutil.c index 2cc0b10b8..38464d2dd 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -98,6 +98,11 @@ png_get_int_32)(png_const_bytep buf) png_uint_16 (PNGAPI png_get_uint_16)(png_const_bytep buf) { + /* ANSI-C requires an int value to accomodate at least 16 bits so this + * works and allows the compiler not to worry about possible narrowing + * on 32 bit systems. (Pre-ANSI systems did not make integers smaller + * than 16 bits either.) + */ unsigned int val = ((unsigned int)(*buf) << 8) + ((unsigned int)(*(buf + 1))); diff --git a/pngwtran.c b/pngwtran.c index 066e1e2c9..1765ef89d 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -220,6 +220,9 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) break; } + + default: + break; } row_info->bit_depth = (png_byte)bit_depth; diff --git a/pngwutil.c b/pngwutil.c index 3377d38c4..71f26259b 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -257,10 +257,12 @@ png_text_compress(png_structp png_ptr, */ /* Set up the compression buffers */ + /* TODO: the following cast hides a potential overflow problem. */ png_ptr->zstream.avail_in = (uInt)text_len; + /* NOTE: assume zlib doesn't overwrite the input */ png_ptr->zstream.next_in = (Bytef *)text; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; + png_ptr->zstream.avail_out = png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; /* This is the same compression loop as in png_write_row() */ do