clock: assert about timestamp overflows
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 19 Jun 2012 12:05:21 +0000 (14:05 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 19 Jun 2012 12:09:02 +0000 (14:09 +0200)
Assert when converting to timeval and timespec about overflows. This can happen
on platforms with 32bits long.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=678181

gst/gstclock.h

index 07b2bc0..20fb4b5 100644 (file)
@@ -183,6 +183,8 @@ typedef gpointer GstClockID;
  */
 #define GST_TIME_TO_TIMEVAL(t,tv)                               \
 G_STMT_START {                                                  \
+  g_assert ("Value of time " #t " is out of timeval's range" && \
+      ((t) / GST_SECOND) < G_MAXLONG);                          \
   (tv).tv_sec  = (glong) (((GstClockTime) (t)) / GST_SECOND);   \
   (tv).tv_usec = (glong) ((((GstClockTime) (t)) -               \
                   ((GstClockTime) (tv).tv_sec) * GST_SECOND)    \
@@ -203,8 +205,10 @@ G_STMT_START {                                                  \
  *
  * Convert a #GstClockTime to a struct timespec (see man pselect)
  */
-#define GST_TIME_TO_TIMESPEC(t,ts)                      \
-G_STMT_START {                                          \
+#define GST_TIME_TO_TIMESPEC(t,ts)                                \
+G_STMT_START {                                                    \
+  g_assert ("Value of time " #t " is out of timespec's range" &&  \
+      ((t) / GST_SECOND) < G_MAXLONG);                            \
   (ts).tv_sec  =  (glong) ((t) / GST_SECOND);                     \
   (ts).tv_nsec = (glong) (((t) - (ts).tv_sec * GST_SECOND) / GST_NSECOND);        \
 } G_STMT_END