Division by zero in innreport

Julien ÉLIE julien at trigofacile.com
Tue Jun 12 18:04:09 UTC 2012


Hi Petr,

> JL>  >  I would suggest to remove the line for "Mar 1 00:00:00 -- Feb 29 23:59:59"
> JL>  >  in innreport.db to fix the problem.
> JL>  >  Maybe it has been generated by a previous version of innreport that had a
> JL>  >  bug;
> 
> JL>  As for innreport for INN 2.5.3, what would be the best behaviour?
> JL>  Maybe checking the validity of a date before using it and not process the
> JL>  line if the date is not coherent?  Should such lines be automatically
> JL>  removed from innreport.db?
> 
> Perhaps, this is a good solution!

On second thought, I believe skipping such lines is better.
This way, we do not lose any data (in case an issue is noticed, the news administrator
may decide to fix it manually in innreport.db -- otherwise, the information would have
be deleted).


Thanks, Peter, for your bug report.



Suggested patch, that will be included in INN 2.5.3.
The release is expected within a week.  At last!


Index: scripts/innreport.in
===================================================================
--- scripts/innreport.in	(révision 9413)
+++ scripts/innreport.in	(copie de travail)
@@ -739,6 +739,8 @@
 }
 
 # Convert a date to number of seconds since epoch.
+# Return undef in case the date is invalid.
+#
 # Leap years are handled correctly, daylight saving is not.
 # Usage: $num = &ConvDate ($date, $wrap_around);
 # Date format is "2012 Aug 22 01:49:40".
@@ -767,8 +769,14 @@
   # Take the previous year if a change of year has been detected and
   # the date is after May, 1st.
   $y-- if $wrap > 0 and $m > 4;
+
   # Convert the given date to the number of seconds since epoch.
-  return Time::Local::timelocal($s, $mn, $h, $d, $m, $y);
+  # Use an eval block to catch the error in case of an invalid date.
+  my $epochtime = undef;
+  eval {
+    $epochtime = Time::Local::timelocal($s, $mn, $h, $d, $m, $y);
+  };
+  return $epochtime;
 }
 
 # Compare 2 filenames
@@ -1120,6 +1128,11 @@
         }
 	my $start_sec = &ConvDate ($year . ' ' . $start, 0);
 	my $end_sec = &ConvDate ($year . ' ' . $end, 0);
+        if (!defined($start_sec) or !defined($end_sec))
+        { 
+          warn "Invalid date in DB file ignored: $k" if ($DEBUG);
+          next;
+        }
         if ($start_sec - $end_sec == 0)
         {
           warn "Time range 0 in DB file ignored: $k" if ($DEBUG);



-- 
Julien ÉLIE

« Pour célébrer ce jour heureux, buvons un coup, buvons-en deux. »
  (Aristophane)


More information about the inn-workers mailing list