diff --git a/ANNOUNCE b/ANNOUNCE index 1bc86d4bf..8dc0ccc96 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.4.17beta02 - August 19, 2015 +Libpng 1.4.17beta02 - August 21, 2015 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. @@ -49,7 +49,8 @@ version 1.4.17beta01 [August 19, 2015] in ANSI-C (unlike 0x80000000 in the signed case) the checking that occurs later can catch them (John Bowler). -version 1.4.17beta02 [August 19, 2015] +version 1.4.17beta02 [August 21, 2015] + Fixed png_save_int_32 when int is not 2's complement (John Bowler). Send comments/corrections/commendations to glennrp at users.sourceforge.net or to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index d9099eb4a..bcfe3f9c2 100644 --- a/CHANGES +++ b/CHANGES @@ -2979,7 +2979,8 @@ version 1.4.17beta01 [August 19, 2015] in ANSI-C (unlike 0x80000000 in the signed case) the checking that occurs later can catch them (John Bowler). -version 1.4.17beta02 [August 19, 2015] +version 1.4.17beta02 [August 21, 2015] + Fixed png_save_int_32 when int is not 2's complement (John Bowler). Send comments/corrections/commendations to glennrp at users.sourceforge.net or to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngwutil.c b/pngwutil.c index 04ca8f518..525485b13 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -30,17 +30,20 @@ png_save_uint_32(png_bytep buf, png_uint_32 i) } #ifdef PNG_SAVE_INT_32_SUPPORTED -/* The png_save_int_32 function assumes integers are stored in two's - * complement format. If this isn't the case, then this routine needs to - * be modified to write data in two's complement format. +/* PNG signed integers are saved in 32-bit 2's complement format. ANSI C-90 + * defines a cast of a signed integer to an unsigned integer either to preserve + * the value, if it is positive, or to calculate: + * + * (UNSIGNED_MAX+1) + integer + * + * Where UNSIGNED_MAX is the appropriate maximum unsigned value, so when the + * negative integral value is added the result will be an unsigned value + * correspnding to the 2's complement representation. */ void PNGAPI png_save_int_32(png_bytep buf, png_int_32 i) { - buf[0] = (png_byte)((i >> 24) & 0xff); - buf[1] = (png_byte)((i >> 16) & 0xff); - buf[2] = (png_byte)((i >> 8) & 0xff); - buf[3] = (png_byte)(i & 0xff); + png_save_uint_32(buf, i); } #endif