From b45416921bbb63c7bbfe6ddafb7b75ac4aeccb75 Mon Sep 17 00:00:00 2001 From: John Bowler Date: Mon, 30 Apr 2012 06:31:54 -0500 Subject: [PATCH] [libpng16] Removed need for -Wno-cast-align with clang. clang correctly warns on alignment increasing pointer casts when -Wcast-align is passed. This fixes the cases clang warns about either (pngread.c) by eliminating the casts from png_bytep to png_uint_16p or, for pngrutil.c where the cast is previously verified or pngstest.c where it is OK by introducing new png_aligncast macros to do the cast in a way that clang accepts. --- ANNOUNCE | 10 ++++++-- CHANGES | 8 +++++- png.c | 4 +-- png.h | 10 ++++---- pngconf.h | 2 +- pngpriv.h | 6 +++++ pngread.c | 74 +++++++++++++++++++++++++++++++++--------------------- pngrutil.c | 10 +++++--- 8 files changed, 80 insertions(+), 44 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 33dc63e84..dda85177d 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.6.0beta22 - April 28, 2012 +Libpng 1.6.0beta22 - April 30, 2012 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -360,7 +360,13 @@ Version 1.6.0beta21 [April 27, 2012] Added -lssp_nonshared in a comment in scripts/makefile.freebsd and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE. -Version 1.6.0beta22 [April 28, 2012] +Version 1.6.0beta22 [April 30, 2012] + Removed need for -Wno-cast-align with clang. clang correctly warns on + alignment increasing pointer casts when -Wcast-align is passed. This + fixes the cases clang warns about either (pngread.c) by eliminating the + casts from png_bytep to png_uint_16p or, for pngrutil.c where the cast + is previously verified or pngstest.c where it is OK by introducing new + png_aligncast macros to do the cast in a way that clang accepts. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index 37e20f3b6..771c53ef0 100644 --- a/CHANGES +++ b/CHANGES @@ -4111,7 +4111,13 @@ Version 1.6.0beta21 [April 27, 2012] Added -lssp_nonshared in a comment in scripts/makefile.freebsd and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE. -Version 1.6.0beta22 [April 28, 2012] +Version 1.6.0beta22 [April 30, 2012] + Removed need for -Wno-cast-align with clang. clang correctly warns on + alignment increasing pointer casts when -Wcast-align is passed. This + fixes the cases clang warns about either (pngread.c) by eliminating the + casts from png_bytep to png_uint_16p or, for pngrutil.c where the cast + is previously verified or pngstest.c where it is OK by introducing new + png_aligncast macros to do the cast in a way that clang accepts. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/png.c b/png.c index f93f93c01..95cbbb5d6 100644 --- a/png.c +++ b/png.c @@ -747,13 +747,13 @@ png_get_copyright(png_const_structrp png_ptr) #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ - "libpng version 1.6.0beta22 - April 28, 2012" PNG_STRING_NEWLINE \ + "libpng version 1.6.0beta22 - April 30, 2012" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2012 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # else - return "libpng version 1.6.0beta22 - April 28, 2012\ + return "libpng version 1.6.0beta22 - April 30, 2012\ Copyright (c) 1998-2012 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; diff --git a/png.h b/png.h index 825547959..7ae10ebeb 100644 --- a/png.h +++ b/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.6.0beta22 - April 28, 2012 + * libpng version 1.6.0beta22 - April 30, 2012 * Copyright (c) 1998-2012 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -11,7 +11,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.6.0beta22 - April 28, 2012: Glenn + * libpng versions 0.97, January 1998, through 1.6.0beta22 - April 30, 2012: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -198,7 +198,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.6.0beta22, April 28, 2012, are + * libpng versions 1.2.6, August 15, 2004, through 1.6.0beta22, April 30, 2012, are * Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: @@ -310,7 +310,7 @@ * Y2K compliance in libpng: * ========================= * - * April 28, 2012 + * April 30, 2012 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. @@ -376,7 +376,7 @@ /* Version information for png.h - this should match the version in png.c */ #define PNG_LIBPNG_VER_STRING "1.6.0beta22" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.6.0beta22 - April 28, 2012\n" + " libpng version 1.6.0beta22 - April 30, 2012\n" #define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_DLLNUM 16 diff --git a/pngconf.h b/pngconf.h index e7265f798..1b69728a4 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.6.0beta22 - April 28, 2012 + * libpng version 1.6.0beta22 - April 30, 2012 * * Copyright (c) 1998-2012 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/pngpriv.h b/pngpriv.h index 8ec7dce75..e09a10e4d 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -312,9 +312,15 @@ typedef const png_uint_16p * png_const_uint_16pp; #ifdef __cplusplus # define png_voidcast(type, value) static_cast(value) # define png_constcast(type, value) const_cast(value) +# define png_aligncast(type, value) \ + static_cast(static_cast(value)) +# define png_aligncastconst(type, value) \ + static_cast(static_cast(value)) #else # define png_voidcast(type, value) (value) # define png_constcast(type, value) ((type)(value)) +# define png_aligncast(type, value) ((void*)(value)) +# define png_aligncastconst(type, value) ((const void*)(value)) #endif /* __cplusplus */ /* Some fixed point APIs are still required even if not exported because diff --git a/pngread.c b/pngread.c index 399604121..a0ab6f301 100644 --- a/pngread.c +++ b/pngread.c @@ -1145,8 +1145,8 @@ typedef struct png_voidp colormap; png_const_colorp background; /* Local variables: */ - png_bytep local_row; - png_bytep first_row; + png_voidp local_row; + png_voidp first_row; ptrdiff_t row_bytes; /* step between rows */ int file_encoding; /* E_ values above */ png_fixed_point gamma_to_linear; /* For E_FILE, reciprocal of gamma */ @@ -2771,7 +2771,7 @@ png_image_read_and_map(png_voidp argument) png_uint_32 height = image->height; png_uint_32 width = image->width; int proc = display->colormap_processing; - png_bytep first_row = display->first_row; + png_bytep first_row = png_voidcast(png_bytep, display->first_row); ptrdiff_t step_row = display->row_bytes; int pass; @@ -2801,7 +2801,7 @@ png_image_read_and_map(png_voidp argument) for (; ylocal_row; + png_bytep inrow = png_voidcast(png_bytep, display->local_row); png_bytep outrow = first_row + y * step_row; png_const_bytep end_row = outrow + width; @@ -3011,14 +3011,18 @@ png_image_read_colormapped(png_voidp argument) * size libpng requires and call the relevant processing routine safely. */ { - png_bytep first_row = png_voidcast(png_bytep, display->buffer); + png_voidp first_row = display->buffer; ptrdiff_t row_bytes = display->row_stride; /* The following expression is designed to work correctly whether it gives * a signed or an unsigned result. */ if (row_bytes < 0) - first_row += (image->height-1) * (-row_bytes); + { + char *ptr = png_voidcast(char*, first_row); + ptr += (image->height-1) * (-row_bytes); + first_row = png_voidcast(png_voidp, ptr); + } display->first_row = first_row; display->row_bytes = row_bytes; @@ -3027,8 +3031,7 @@ png_image_read_colormapped(png_voidp argument) if (passes == 0) { int result; - png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr, - png_get_rowbytes(png_ptr, info_ptr))); + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); display->local_row = row; result = png_safe_execute(image, png_image_read_and_map, display); @@ -3045,7 +3048,7 @@ png_image_read_colormapped(png_voidp argument) while (--passes >= 0) { png_uint_32 y = image->height; - png_bytep row = display->first_row; + png_bytep row = png_voidcast(png_bytep, display->first_row); while (y-- > 0) { @@ -3086,7 +3089,6 @@ png_image_read_composite(png_voidp argument) { png_uint_32 height = image->height; png_uint_32 width = image->width; - png_bytep first_row = display->first_row; ptrdiff_t step_row = display->row_bytes; unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1; int pass; @@ -3118,13 +3120,17 @@ png_image_read_composite(png_voidp argument) for (; ylocal_row; - png_bytep outrow = first_row + y * step_row; - png_const_bytep end_row = outrow + width * channels; + png_bytep inrow = png_voidcast(png_bytep, display->local_row); + png_bytep outrow; + png_const_bytep end_row; /* Read the row, which is packed: */ png_read_row(png_ptr, inrow, NULL); + outrow = png_voidcast(png_bytep, display->first_row); + outrow += y * step_row; + end_row = outrow + width * channels; + /* Now do the composition on each pixel in this row. */ outrow += startx; for (; outrow < end_row; outrow += stepx) @@ -3242,12 +3248,13 @@ png_image_read_background(png_voidp argument) * Unlike the code above ALPHA_OPTIMIZED has *not* been done. */ { - png_bytep first_row = display->first_row; + png_bytep first_row = png_voidcast(png_bytep, display->first_row); ptrdiff_t step_row = display->row_bytes; for (pass = 0; pass < passes; ++pass) { - png_bytep row = display->first_row; + png_bytep row = png_voidcast(png_bytep, + display->first_row); unsigned int startx, stepx, stepy; png_uint_32 y; @@ -3274,7 +3281,8 @@ png_image_read_background(png_voidp argument) { for (; ylocal_row; + png_bytep inrow = png_voidcast(png_bytep, + display->local_row); png_bytep outrow = first_row + y * step_row; png_const_bytep end_row = outrow + width; @@ -3318,7 +3326,8 @@ png_image_read_background(png_voidp argument) for (; ylocal_row; + png_bytep inrow = png_voidcast(png_bytep, + display->local_row); png_bytep outrow = first_row + y * step_row; png_const_bytep end_row = outrow + width; @@ -3364,8 +3373,12 @@ png_image_read_background(png_voidp argument) * handles the alpha-first option. */ { - png_bytep first_row = display->first_row; - ptrdiff_t step_row = display->row_bytes; + png_uint_16p first_row = png_voidcast(png_uint_16p, + display->first_row); + /* The division by two is safe because the caller passed in a + * stride which was multiplied by 2 (below) to get row_bytes. + */ + ptrdiff_t step_row = display->row_bytes / 2; int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0; unsigned int outchannels = 1+preserve_alpha; int swap_alpha = 0; @@ -3403,12 +3416,13 @@ png_image_read_background(png_voidp argument) for (; ylocal_row, NULL); - inrow = (png_const_uint_16p)display->local_row; + png_read_row(png_ptr, png_voidcast(png_bytep, + display->local_row), NULL); + inrow = png_voidcast(png_const_uint_16p, display->local_row); /* Now do the pre-multiplication on each pixel in this row. */ @@ -3806,7 +3820,7 @@ png_image_read_direct(png_voidp argument) * display acts as a flag. */ { - png_bytep first_row = png_voidcast(png_bytep, display->buffer); + png_voidp first_row = display->buffer; ptrdiff_t row_bytes = display->row_stride; if (linear) @@ -3816,7 +3830,11 @@ png_image_read_direct(png_voidp argument) * a signed or an unsigned result. */ if (row_bytes < 0) - first_row += (image->height-1) * (-row_bytes); + { + char *ptr = png_voidcast(char*, first_row); + ptr += (image->height-1) * (-row_bytes); + first_row = png_voidcast(png_voidp, ptr); + } display->first_row = first_row; display->row_bytes = row_bytes; @@ -3825,8 +3843,7 @@ png_image_read_direct(png_voidp argument) if (do_local_compose) { int result; - png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr, - png_get_rowbytes(png_ptr, info_ptr))); + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); display->local_row = row; result = png_safe_execute(image, png_image_read_composite, display); @@ -3839,8 +3856,7 @@ png_image_read_direct(png_voidp argument) else if (do_local_background == 2) { int result; - png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr, - png_get_rowbytes(png_ptr, info_ptr))); + png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); display->local_row = row; result = png_safe_execute(image, png_image_read_background, display); @@ -3857,7 +3873,7 @@ png_image_read_direct(png_voidp argument) while (--passes >= 0) { png_uint_32 y = image->height; - png_bytep row = display->first_row; + png_bytep row = png_voidcast(png_bytep, display->first_row); while (y-- > 0) { diff --git a/pngrutil.c b/pngrutil.c index efcac780d..75e7d5807 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -3261,8 +3261,9 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) bytes_to_copy % sizeof (png_uint_32) == 0 && bytes_to_jump % sizeof (png_uint_32) == 0) { - png_uint_32p dp32 = (png_uint_32p)dp; - png_const_uint_32p sp32 = (png_const_uint_32p)sp; + png_uint_32p dp32 = png_aligncast(png_uint_32p,dp); + png_const_uint_32p sp32 = png_aligncastconst( + png_const_uint_32p, sp); unsigned int skip = (bytes_to_jump-bytes_to_copy) / sizeof (png_uint_32); @@ -3302,8 +3303,9 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) */ else { - png_uint_16p dp16 = (png_uint_16p)dp; - png_const_uint_16p sp16 = (png_const_uint_16p)sp; + png_uint_16p dp16 = png_aligncast(png_uint_16p, dp); + png_const_uint_16p sp16 = png_aligncastconst( + png_const_uint_16p, sp); unsigned int skip = (bytes_to_jump-bytes_to_copy) / sizeof (png_uint_16);