utils: avoid dividing by zero when multiplying y/z by 0/x
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Wed, 9 Apr 2014 15:40:27 +0000 (16:40 +0100)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Wed, 9 Apr 2014 15:41:47 +0000 (16:41 +0100)
The gcd of 0/x is 0, and this is then used as a denominator.

gst/gstutils.c

index 9f6ffa6..867fd56 100644 (file)
@@ -3422,6 +3422,13 @@ gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
   g_return_val_if_fail (a_d != 0, FALSE);
   g_return_val_if_fail (b_d != 0, FALSE);
 
+  /* early out if either is 0, as its gcd would be 0 */
+  if (a_n == 0 || b_n == 0) {
+    *res_n = 0;
+    *res_d = 1;
+    return TRUE;
+  }
+
   gcd = gst_util_greatest_common_divisor (a_n, a_d);
   a_n /= gcd;
   a_d /= gcd;