summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2016-12-26 19:27:37 -0600
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2016-12-26 19:27:37 -0600
commit80d36775d4829fe18e19ac3e459028b386d141d2 (patch)
tree6cb5216def986de315771a617fa4889c24370144
parent742c66f37c939c3686fd8575c636d573825e1a92 (diff)
parent95e0094f85c36cfeec0a1385cb932157236c4231 (diff)
downloadlibpng-80d36775d4829fe18e19ac3e459028b386d141d2.tar.gz
Merge branch 'libpng15' of git://github.com/jbowler/libpng into libpng15
-rw-r--r--contrib/libtests/pngvalid.c7
-rw-r--r--png.c31
-rw-r--r--pngpriv.h7
-rw-r--r--pngtrans.c14
4 files changed, 32 insertions, 27 deletions
diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c
index 9b85c3ef3..330e26393 100644
--- a/contrib/libtests/pngvalid.c
+++ b/contrib/libtests/pngvalid.c
@@ -4010,8 +4010,11 @@ check_interlace_type(int const interlace_type)
# define do_own_interlace 1
#endif /* WRITE_INTERLACING tests */
-#define CAN_WRITE_INTERLACE\
- PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
+#if PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
+# define CAN_WRITE_INTERLACE 1
+#else
+# define CAN_WRITE_INTERLACE 0
+#endif
/* Do the same thing for read interlacing; this controls whether read tests do
* their own de-interlace or use libpng.
diff --git a/png.c b/png.c
index 6922200ac..0e394207d 100644
--- a/png.c
+++ b/png.c
@@ -776,6 +776,8 @@ png_access_version_number(void)
/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */
# ifdef PNG_CHECK_cHRM_SUPPORTED
+static void png_64bit_product(long v1, long v2, long *hi_product,
+ unsigned long *lo_product);
int /* PRIVATE */
png_check_cHRM_fixed(png_structp png_ptr,
@@ -784,7 +786,8 @@ png_check_cHRM_fixed(png_structp png_ptr,
png_fixed_point blue_x, png_fixed_point blue_y)
{
int ret = 1;
- unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
+ long xy_hi,yx_hi;
+ unsigned long xy_lo,yx_lo;
png_debug(1, "in function png_check_cHRM_fixed");
@@ -2169,29 +2172,31 @@ png_reciprocal2(png_fixed_point a, png_fixed_point b)
* A and D, and X || Y is (X << 16) + Y.
*/
-void /* PRIVATE */
-png_64bit_product (long v1, long v2, unsigned long *hi_product,
+static void
+png_64bit_product(long v1, long v2, long *hi_product,
unsigned long *lo_product)
{
- int a, b, c, d;
- long lo, hi, x, y;
+ long a, b, c, d;
+ unsigned long lo;
+ long hi, x, y;
- a = (v1 >> 16) & 0xffff;
+ a = v1 >> 16;
b = v1 & 0xffff;
- c = (v2 >> 16) & 0xffff;
+ c = v2 >> 16;
d = v2 & 0xffff;
- lo = b * d; /* BD */
+ lo = b;
+ lo *= d; /* BD */
x = a * d + c * b; /* AD + CB */
- y = ((lo >> 16) & 0xffff) + x;
+ y = (lo >> 16) + x;
- lo = (lo & 0xffff) | ((y & 0xffff) << 16);
- hi = (y >> 16) & 0xffff;
+ lo = (lo & 0xffff) | ((y & 0xffffU) << 16);
+ hi = y >> 16;
hi += a * c; /* AC */
- *hi_product = (unsigned long)hi;
- *lo_product = (unsigned long)lo;
+ *hi_product = hi;
+ *lo_product = lo;
}
#endif /* CHECK_cHRM */
diff --git a/pngpriv.h b/pngpriv.h
index 8bdccccaf..e6ca9bf0d 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -1362,13 +1362,6 @@ PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr,
png_fixed_point int_blue_y));
#endif
-#ifdef PNG_CHECK_cHRM_SUPPORTED
-/* Added at libpng version 1.2.34 and 1.4.0 */
-/* Currently only used by png_check_cHRM_fixed */
-PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2,
- unsigned long *hi_product, unsigned long *lo_product));
-#endif
-
#ifdef PNG_cHRM_SUPPORTED
/* Added at libpng version 1.5.5 */
typedef struct png_xy
diff --git a/pngtrans.c b/pngtrans.c
index a5df5afe0..dcd4d98b4 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -629,12 +629,16 @@ png_do_check_palette_indexes(png_structp png_ptr, png_row_infop row_info)
png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
{
/* Calculations moved outside switch in an attempt to stop different
- * compiler warnings. 'padding' is in *bits* within the last byte, it is
- * an 'int' because pixel_depth becomes an 'int' in the expression below,
- * and this calculation is used because it avoids warnings that other
- * forms produced on either GCC or MSVC.
+ * compiler warnings.
+ *
+ * 1.5.28: This rewritten version attempts to remove the unsigned integer
+ * overflow from the prior version. While this was well defined it
+ * resulted in unsigned overflow detection in clang. Since the result is
+ * always in the range 0..7 only the low three bits of of the various
+ * intermediates are every required, so:
*/
- int padding = (-row_info->pixel_depth * row_info->width) & 7;
+ unsigned int padding =
+ ((8 - (row_info->pixel_depth & 7)) * (row_info->width & 7)) & 7;
png_bytep rp = png_ptr->row_buf + row_info->rowbytes;
switch (row_info->bit_depth)