diff --git a/ANNOUNCE b/ANNOUNCE index 03b29119c..da13b1796 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.5.24beta02 - August 19, 2015 +Libpng 1.5.24beta02 - 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. @@ -43,7 +43,8 @@ Version 1.5.24beta01 [August 19, 2015] in ANSI-C (unlike 0x80000000 in the signed case) the checking that occurs later can catch them (John Bowler). -Version 1.5.24beta02 [August 19, 2015] +Version 1.5.24beta02 [August 21, 2015] + Fixed png_save_int_32 when int is not 2's complement (John Bowler). Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index 6bc84a7c8..c530ba9f3 100644 --- a/CHANGES +++ b/CHANGES @@ -4389,7 +4389,8 @@ Version 1.5.24beta01 [August 19, 2015] in ANSI-C (unlike 0x80000000 in the signed case) the checking that occurs later can catch them (John Bowler). -Version 1.5.24beta02 [August 19, 2015] +Version 1.5.24beta02 [August 21, 2015] + Fixed png_save_int_32 when int is not 2's complement (John Bowler). Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngwutil.c b/pngwutil.c index 04883d43e..fc028637a 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -30,19 +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. Note that, - * the following works correctly even if png_int_32 has more than 32 bits - * (compare the more complex code required on read for sign extention.) +/* 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