diff options
author | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2015-01-27 15:54:37 -0600 |
---|---|---|
committer | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2015-01-27 15:54:37 -0600 |
commit | 3043819fb2718b8209d919121fcacd7d76f46380 (patch) | |
tree | 58ac5778b0343ff57cd15bfbbd0eb8c3f2197883 | |
parent | 565e1bc1ae39d460119513946f3734fffc808154 (diff) | |
download | libpng-3043819fb2718b8209d919121fcacd7d76f46380.tar.gz |
[libpng17] Quieted some Coverity warnings
-rw-r--r-- | png.c | 29 | ||||
-rw-r--r-- | pngrtran.c | 49 | ||||
-rw-r--r-- | pngrutil.c | 3 |
3 files changed, 50 insertions, 31 deletions
@@ -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. */ #ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = 1E15/a; - r /= b; - r = floor(r+.5); + if (a != 0 && b != 0) + { + double r = 1E15/a; + r /= b; + r = floor(r+.5); - if (r <= 2147483647. && r >= -2147483648.) - return (png_fixed_point)r; + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; #else - /* 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 screen gamma so it - * doesn't matter that the smallest number it can produce is 1/21474, not - * 1/100000 - */ - png_fixed_point res = png_product2(a, b); + /* 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 + * screen gamma so it doesn't matter that the smallest number it can + * produce is 1/21474, not 1/100000 + */ + png_fixed_point res = png_product2(a, b); - if (res != 0) - return png_reciprocal(res); + if (res != 0) + return png_reciprocal(res); #endif + } return 0; /* overflow */ } diff --git a/pngrtran.c b/pngrtran.c index 0ea587b0f..fb78ca43f 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -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), convert_gamma_value(png_ptr, file_gamma)); } -# endif /* FLOATING_POINT_SUPPORTED */ +# endif /* FLOATING_POINT */ #endif /* READ_GAMMA */ #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 add = (shift > 0 ? 1U<<(shift-1) : 0); - 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]; - png_composite_16(w, v, alpha, back_1.green); - palette[i].green = png_ptr->gamma_from_1[(w+add)>>shift]; - - v = png_ptr->gamma_to_1[palette[i].blue]; - png_composite_16(w, v, alpha, back_1.blue); - palette[i].blue = png_ptr->gamma_from_1[(w+add)>>shift]; + if (png_ptr->gamma_to_1 != NULL) + { + 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]; + png_composite_16(w, v, alpha, back_1.green); + palette[i].green = + png_ptr->gamma_from_1[(w+add)>>shift]; + + v = png_ptr->gamma_to_1[palette[i].blue]; + png_composite_16(w, v, alpha, back_1.blue); + 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].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 * 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]; - palette[i].green = png_ptr->gamma_table[palette[i].green]; - palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + for (i = 0; i < num_palette; i++) + { + 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. */ @@ -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; +#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; + + 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) { diff --git a/pngrutil.c b/pngrutil.c index 97c29f582..5a5e50f5c 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -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_ptr->trans_color)); - png_ptr->trans_alpha = info_ptr->trans_alpha; + if (info_ptr != NULL) + png_ptr->trans_alpha = info_ptr->trans_alpha; } #endif |