[lipng17] Do not build png_product2() when it is unused and work around

one more Coverity-scan dead-code warning.
This commit is contained in:
Glenn Randers-Pehrson 2015-02-07 08:54:07 -06:00
parent d7312be749
commit 6ce2d220b4
5 changed files with 45 additions and 39 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.7.0beta48 - January 29, 2015 Libpng 1.7.0beta48 - February 7, 2015
This is not intended to be a public release. It will be replaced 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. within a few weeks by a public version or by another test version.
@ -697,7 +697,9 @@ Version 1.7.0beta47 [January 29, 2015]
Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
pngset.c to avoid warnings about dead code. pngset.c to avoid warnings about dead code.
Version 1.7.0beta48 [January 29, 2015] Version 1.7.0beta48 [February 7, 2015]
Work around one more Coverity-scan dead-code warning.
Do not build png_product2() when it is unused.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -4986,7 +4986,9 @@ Version 1.7.0beta47 [January 29, 2015]
Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
pngset.c to avoid warnings about dead code. pngset.c to avoid warnings about dead code.
Version 1.7.0beta48 [January 29, 2015] Version 1.7.0beta48 [February 7, 2015]
Work around one more Coverity-scan dead-code warning.
Do not build png_product2() when it is unused.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

23
png.c
View File

@ -694,13 +694,13 @@ png_get_copyright(png_const_structrp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.7.0beta48 - February 4, 2015" PNG_STRING_NEWLINE \ "libpng version 1.7.0beta48 - February 7, 2015" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2015 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2015 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.7.0beta48 - February 4, 2015\ return "libpng version 1.7.0beta48 - February 7, 2015\
Copyright (c) 1998-2015 Glenn Randers-Pehrson\ Copyright (c) 1998-2015 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@ -3319,34 +3319,28 @@ png_gamma_significant(png_fixed_point gamma_val)
#endif #endif
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
#if defined(PNG_16BIT_SUPPORTED) || !defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) #ifdef PNG_16BIT_SUPPORTED
#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
/* A local convenience routine. */ /* A local convenience routine. */
static png_fixed_point static png_fixed_point
png_product2(png_fixed_point a, png_fixed_point b) png_product2(png_fixed_point a, png_fixed_point b)
{ {
/* The required result is 1/a * 1/b; the following preserves accuracy. */ /* The required result is 1/a * 1/b; the following preserves accuracy. */
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
double r = a * 1E-5;
r *= b;
r = floor(r+.5);
if (r <= 2147483647. && r >= -2147483648.)
return (png_fixed_point)r;
#else
png_fixed_point res; png_fixed_point res;
if (png_muldiv(&res, a, b, 100000) != 0) if (png_muldiv(&res, a, b, 100000) != 0)
return res; return res;
#endif
return 0; /* overflow */ return 0; /* overflow */
} }
#endif /* 16BIT || !FLOATING_ARITHMETIC */ #endif /* FLOATING_ARITHMETIC */
#endif /* 16BIT */
/* The inverse of the above. */ /* The inverse of the above. */
png_fixed_point png_fixed_point
png_reciprocal2(png_fixed_point a, png_fixed_point b) png_reciprocal2(png_fixed_point a, png_fixed_point b)
{ {
#ifdef PNG_16BIT_SUPPORTED
/* The required result is 1/a * 1/b; the following preserves accuracy. */ /* The required result is 1/a * 1/b; the following preserves accuracy. */
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
if (a != 0 && b != 0) if (a != 0 && b != 0)
@ -3357,6 +3351,7 @@ png_reciprocal2(png_fixed_point a, png_fixed_point b)
if (r <= 2147483647. && r >= -2147483648.) if (r <= 2147483647. && r >= -2147483648.)
return (png_fixed_point)r; return (png_fixed_point)r;
}
#else #else
/* This may overflow because the range of png_fixed_point isn't /* This may overflow because the range of png_fixed_point isn't
* symmetric, but this API is only used for the product of file and * symmetric, but this API is only used for the product of file and
@ -3368,7 +3363,7 @@ png_reciprocal2(png_fixed_point a, png_fixed_point b)
if (res != 0) if (res != 0)
return png_reciprocal(res); return png_reciprocal(res);
#endif #endif
} #endif /* 16BIT */
return 0; /* overflow */ return 0; /* overflow */
} }

View File

@ -2285,8 +2285,14 @@ png_image_read_colormap(png_voidp argument)
output_processing = PNG_CMAP_NONE; output_processing = PNG_CMAP_NONE;
break; break;
} }
#ifdef __COVERITY__
/* Coverity claims that output_encoding cannot be 2 (P_LINEAR)
* here.
*/
back_alpha = 255;
#else
back_alpha = output_encoding == P_LINEAR ? 65535 : 255; back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
#endif
} }
/* output_processing means that the libpng-processed row will be /* output_processing means that the libpng-processed row will be
@ -2411,7 +2417,14 @@ png_image_read_colormap(png_voidp argument)
*/ */
background_index = i; background_index = i;
png_create_colormap_entry(display, i++, back_r, back_g, back_b, png_create_colormap_entry(display, i++, back_r, back_g, back_b,
output_encoding == P_LINEAR ? 65535U : 255U, output_encoding); #ifdef __COVERITY__
/* Coverity claims that output_encoding cannot be 2 (P_LINEAR)
* here.
*/ 255U,
#else
output_encoding == P_LINEAR ? 65535U : 255U,
#endif
output_encoding);
/* For non-opaque input composite on the sRGB background - this /* For non-opaque input composite on the sRGB background - this
* requires inverting the encoding for each component. The input * requires inverting the encoding for each component. The input

View File

@ -2991,18 +2991,11 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
png_uint_16 red, green, blue, w; png_uint_16 red, green, blue, w;
#if 0 /* Coverity doesn't like this */
red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
#else
png_byte hi,lo; png_byte hi,lo;
hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo)); hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo));
hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo)); hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo)); hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo));
#endif
if (red == green && red == blue) if (red == green && red == blue)
{ {
@ -3047,10 +3040,11 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
png_uint_16 red, green, blue, gray16; png_uint_16 red, green, blue, gray16;
png_byte hi,lo;
red = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; hi=*(sp)++; lo=*(sp)++; red = (png_uint_16)((hi << 8) | (lo));
green = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
blue = (png_uint_16)(((*(sp)) << 8) | *(sp + 1)); sp += 2; hi=*(sp)++; lo=*(sp)++; blue = (png_uint_16)((hi << 8) | (lo));
if (red != green || red != blue) if (red != green || red != blue)
rgb_error |= 1; rgb_error |= 1;