From: Glenn Randers-Pehrson Date: Fri, 4 Aug 2017 10:50:29 +0000 (-0400) Subject: Improved tIME wraparound calculations X-Git-Tag: 7.0.6-6~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cdec47d66ae42048331f87beb9e82e787e1e424;p=imagemagick Improved tIME wraparound calculations --- diff --git a/coders/png.c b/coders/png.c index 82c3219cf..f84af76e7 100644 --- a/coders/png.c +++ b/coders/png.c @@ -8186,30 +8186,30 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info, ptime.day=(png_byte) day; ptime.hour=(png_byte) hour+addhours; ptime.minute=(png_byte) minute+addminutes; + ptime.second=(png_byte) second; if (ptime.minute > 60) { ptime.hour++; - if (ptime.hour > 24) - { - ptime.hour = 0; - ptime.day ++; - /* To do: fix this for leap years */ - if (ptime.day > 31 || (ptime.month == 2 && ptime.day > 28) || - ((ptime.month == 4 || ptime.month == 6 || ptime.month == 9 || - ptime.month == 11) && ptime.day > 30)) - { - ptime.day = 1; - ptime.month++; - if (ptime.month > 12) - { - ptime.month=1; - ptime.year++; - } - } - } ptime.minute-=60; } - ptime.second=(png_byte) second; + if (ptime.hour > 24) + { + ptime.day ++; + ptime.hour -=24; + } + /* To do: fix this for leap years */ + if (ptime.day > 31 || (ptime.month == 2 && ptime.day > 28) || + ((ptime.month == 4 || ptime.month == 6 || ptime.month == 9 || + ptime.month == 11) && ptime.day > 30)) + { + ptime.month++; + ptime.day = 1; + } + if (ptime.month > 12) + { + ptime.year++; + ptime.month=1; + } png_set_tIME(ping,info,&ptime); } #endif