[xiph-commits] r3547 - liboggz/trunk/src/tools

conrad at svn.annodex.net conrad at svn.annodex.net
Mon Apr 7 02:03:46 PDT 2008


Author: conrad
Date: 2008-04-07 02:03:45 -0700 (Mon, 07 Apr 2008)
New Revision: 3547

Modified:
   liboggz/trunk/src/tools/oggzinfo.c
Log:
oggzinfo: fix overflow in standard deviation calculation, and avoid a divide
by zero in the unlikely case where we have only one packet.
Patch from ogg.k.ogg.k


Modified: liboggz/trunk/src/tools/oggzinfo.c
===================================================================
--- liboggz/trunk/src/tools/oggzinfo.c	2008-04-06 23:03:50 UTC (rev 3546)
+++ liboggz/trunk/src/tools/oggzinfo.c	2008-04-07 09:03:45 UTC (rev 3547)
@@ -108,7 +108,7 @@
 
   /* Pass 2 */
   long length_avg;
-  long length_deviation_total;
+  ogg_int64_t length_deviation_total;
   double length_stddev;
 };
 
@@ -313,9 +313,13 @@
 {
   double variance;
 
-  variance = (double)stats->length_deviation_total / (double)(stats->count - 1);
-  stats->length_stddev = sqrt (variance);
-
+  if (stats->count <= 1) {
+    stats->length_stddev = 0.0;
+  }
+  else {
+    variance = (double)stats->length_deviation_total / (double)(stats->count - 1);
+    stats->length_stddev = sqrt (variance);
+  }
 }
 
 static void



More information about the commits mailing list