ogg_afh.c: Kill unused vi_bitrate_nominal
[paraslash.git] / time.c
diff --git a/time.c b/time.c
index f659b16f09a6abb39c853d915c529a42dfe732b2..83231c895020245d72cea40cd34cae03e9951a29 100644 (file)
--- a/time.c
+++ b/time.c
@@ -106,16 +106,23 @@ void tv_scale(const unsigned long mult, const struct timeval *tv,
 /**
  * compute fraction of given struct timeval
  *
- * \param div the integer value to divide by
+ * \param divisor the integer value to divide by
  * \param tv the timevalue to divide
  * \param result holds (1 / mult) * tv upon return
  */
-void tv_divide(const unsigned long div, const struct timeval *tv,
+void tv_divide(const unsigned long divisor, const struct timeval *tv,
        struct timeval *result)
 {
-       long unsigned q = tv->tv_usec / div;
-       result->tv_sec = tv->tv_sec / div;
-       result->tv_usec = (tv->tv_sec - result->tv_sec * div) * 1000 * 1000 / div;
+       long unsigned q;
+
+       if (!divisor) {
+               PARA_EMERG_LOG("%s\n", "division by zero");
+               exit(EXIT_FAILURE);
+       }
+       q = tv->tv_usec / divisor;
+       result->tv_sec = tv->tv_sec / divisor;
+       result->tv_usec = (tv->tv_sec - result->tv_sec * divisor)
+               * 1000 * 1000 / divisor;
        if (result->tv_usec + q >= 1000 * 1000) {
                result->tv_sec++;
                result->tv_usec = 1000 * 1000 - result->tv_usec - q;
@@ -141,7 +148,7 @@ int tv_convex_combination(const long a, const struct timeval *tv1,
 {
        struct timeval tmp1, tmp2, tmp3;
        int ret = 1, subtract = ((a > 0 && b < 0) || (a < 0 && b > 0));
-       unsigned long a1 = ABS(a), b1 = ABS(b);
+       unsigned long a1 = PARA_ABS(a), b1 = PARA_ABS(b);
 
        tv_scale(a1, tv1, &tmp1);
        tv_scale(b1, tv2, &tmp2);