modplug: avoid division by zero
authorJonathan Matthew <jonathan@d14n.org>
Thu, 27 Aug 2020 21:53:26 +0000 (07:53 +1000)
committerJonathan Matthew <jonathan@d14n.org>
Thu, 27 Aug 2020 22:10:04 +0000 (08:10 +1000)
Under some conditions, GetMaxPosition() returns zero, which should cause
position queries to fail rather than crash.

ext/modplug/gstmodplug.cc

index 30c5952..af6de48 100644 (file)
@@ -298,11 +298,15 @@ gst_modplug_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
       gst_query_parse_position (query, &format, NULL);
       if (format == GST_FORMAT_TIME) {
         gint64 pos;
-
-        pos = (modplug->song_length * modplug->mSoundFile->GetCurrentPos ());
-        pos /= modplug->mSoundFile->GetMaxPosition ();
-        gst_query_set_position (query, format, pos);
-        res = TRUE;
+        guint32 max;
+
+       max = modplug->mSoundFile->GetMaxPosition();
+       if (max > 0) {
+          pos = (modplug->song_length * modplug->mSoundFile->GetCurrentPos ()) /
+            max;
+          gst_query_set_position (query, format, pos);
+          res = TRUE;
+        }
       }
     }
       break;