[libpng17] Quieted some Coverity warnings

This commit is contained in:
Glenn Randers-Pehrson 2015-01-27 15:54:37 -06:00
parent 565e1bc1ae
commit 3043819fb2
3 changed files with 48 additions and 29 deletions

29
png.c
View File

@ -3348,23 +3348,26 @@ png_reciprocal2(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 #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
double r = 1E15/a; if (a != 0 && b != 0)
r /= b; {
r = floor(r+.5); double r = 1E15/a;
r /= b;
r = floor(r+.5);
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 symmetric, /* This may overflow because the range of png_fixed_point isn't
* but this API is only used for the product of file and screen gamma so it * symmetric, but this API is only used for the product of file and
* doesn't matter that the smallest number it can produce is 1/21474, not * screen gamma so it doesn't matter that the smallest number it can
* 1/100000 * produce is 1/21474, not 1/100000
*/ */
png_fixed_point res = png_product2(a, b); png_fixed_point res = png_product2(a, b);
if (res != 0) if (res != 0)
return png_reciprocal(res); return png_reciprocal(res);
#endif #endif
}
return 0; /* overflow */ return 0; /* overflow */
} }

View File

@ -841,7 +841,7 @@ png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma), png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
convert_gamma_value(png_ptr, file_gamma)); convert_gamma_value(png_ptr, file_gamma));
} }
# endif /* FLOATING_POINT_SUPPORTED */ # endif /* FLOATING_POINT */
#endif /* READ_GAMMA */ #endif /* READ_GAMMA */
#ifdef PNG_READ_EXPAND_SUPPORTED #ifdef PNG_READ_EXPAND_SUPPORTED
@ -1663,20 +1663,24 @@ png_init_read_transformations(png_structrp png_ptr)
unsigned int shift = png_ptr->gamma_shift; unsigned int shift = png_ptr->gamma_shift;
unsigned int add = (shift > 0 ? 1U<<(shift-1) : 0); unsigned int add = (shift > 0 ? 1U<<(shift-1) : 0);
v = png_ptr->gamma_to_1[palette[i].red]; if (png_ptr->gamma_to_1 != NULL)
png_composite_16(w, v, alpha, back_1.red); {
palette[i].red = png_ptr->gamma_from_1[(w+add)>>shift]; v = png_ptr->gamma_to_1[palette[i].red];
png_composite_16(w, v, alpha, back_1.red);
palette[i].red = png_ptr->gamma_from_1[(w+add)>>shift];
v = png_ptr->gamma_to_1[palette[i].green]; v = png_ptr->gamma_to_1[palette[i].green];
png_composite_16(w, v, alpha, back_1.green); png_composite_16(w, v, alpha, back_1.green);
palette[i].green = png_ptr->gamma_from_1[(w+add)>>shift]; palette[i].green =
png_ptr->gamma_from_1[(w+add)>>shift];
v = png_ptr->gamma_to_1[palette[i].blue]; v = png_ptr->gamma_to_1[palette[i].blue];
png_composite_16(w, v, alpha, back_1.blue); png_composite_16(w, v, alpha, back_1.blue);
palette[i].blue = png_ptr->gamma_from_1[(w+add)>>shift]; palette[i].blue = png_ptr->gamma_from_1[(w+add)>>shift];
}
} }
} }
else else if (png_ptr->gamma_table != NULL)
{ {
palette[i].red = png_ptr->gamma_table[palette[i].red]; palette[i].red = png_ptr->gamma_table[palette[i].red];
palette[i].green = png_ptr->gamma_table[palette[i].green]; palette[i].green = png_ptr->gamma_table[palette[i].green];
@ -1712,11 +1716,14 @@ png_init_read_transformations(png_structrp png_ptr)
/* NOTE: there are other transformations that should probably be in /* NOTE: there are other transformations that should probably be in
* here too. * here too.
*/ */
for (i = 0; i < num_palette; i++) if (png_ptr->gamma_table != NULL)
{ {
palette[i].red = png_ptr->gamma_table[palette[i].red]; for (i = 0; i < num_palette; i++)
palette[i].green = png_ptr->gamma_table[palette[i].green]; {
palette[i].blue = png_ptr->gamma_table[palette[i].blue]; palette[i].red = png_ptr->gamma_table[palette[i].red];
palette[i].green = png_ptr->gamma_table[palette[i].green];
palette[i].blue = png_ptr->gamma_table[palette[i].blue];
}
} }
/* Done the gamma correction. */ /* Done the gamma correction. */
@ -2985,9 +2992,17 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
{ {
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; red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
green = (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; blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
#else
png_byte hi,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)++; blue = (png_uint_16)((hi << 8) | (lo));
#endif
if (red == green && red == blue) if (red == green && red == blue)
{ {

View File

@ -1834,7 +1834,8 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
&(png_ptr->trans_color)); &(png_ptr->trans_color));
png_ptr->trans_alpha = info_ptr->trans_alpha; if (info_ptr != NULL)
png_ptr->trans_alpha = info_ptr->trans_alpha;
} }
#endif #endif