]> granicus.if.org Git - imagemagick/commitdiff
Improved tIME wraparound calculations
authorGlenn Randers-Pehrson <glennrp@gmail.com>
Fri, 4 Aug 2017 10:50:29 +0000 (06:50 -0400)
committerGlenn Randers-Pehrson <glennrp@gmail.com>
Fri, 4 Aug 2017 10:50:29 +0000 (06:50 -0400)
coders/png.c

index 82c3219cf88c405027860828fd4703b963d81f5e..f84af76e7a420fd7ed8c4664701bdacee6911394 100644 (file)
@@ -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