[Bug 678181] New: Compilation error when using GST_TIME_TO_TIMEVAL()...

GStreamer (bugzilla.gnome.org) bugzilla at gnome.org
Fri Jun 15 11:15:07 PDT 2012


https://bugzilla.gnome.org/show_bug.cgi?id=678181
  GStreamer | gstreamer (core) | git

           Summary: Compilation error when using GST_TIME_TO_TIMEVAL()...
    Classification: Platform
           Product: GStreamer
           Version: git
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: Normal
         Component: gstreamer (core)
        AssignedTo: gstreamer-bugs at lists.freedesktop.org
        ReportedBy: sebras at hotmail.com
         QAContact: gstreamer-bugs at lists.freedesktop.org
     GNOME version: ---


When trying to compile code looking like this:

  GTimeVal tv;
  GST_TIME_TO_TIMEVAL (GST_CLOCK_TIME_NONE, tv);

or like this:

  GTimeVal tv;
  GST_TIME_TO_TIMEVAL (4294967296000000000ULL, tv);

I will, on a 32-bit machine, get an error message:

  error: overflow in implicit constant conversion [-Werror=overflow]

Note that (surprisingly) no error is given for this code:

  GTimeVal tv;
  GstClockTime tmp = 4294967296000000000ULL;
  GST_TIME_TO_TIMEVAL (tmp, tv);

Neither piece of code will give any kind of compile-time or
run-time error on a 64-bit machine.

After reading the code and discussing this on #gstreamer it seems
as if the consensus is that GTimeVal can not represent undefined
clock times or times larger than 2^32 - 1 seconds. This means
that the first snippet of code above is just plain wrong, however
the two other snippets of code are correct in the sense that they
represent valid (but large) values of GstClockTime.

This prompted me to created the attached patch which both
truncates the resulting timeval values to that of its members
(which means that no compile-time errors are generated for 32-bit
machines) and adds a g_assert () explaining what the problem is
(on 32 and 64-bit machines alike):

  assertion failed: ("Value of time " "GST_CLOCK_TIME_NONE" " is out of
timeval's range" && ((GstClockTime) (((GstClockTime) -1))) < (((GstClockTime)
(G_MAXUINT32 - 1U)) * GST_SECOND))
  assertion failed: ("Value of time " "4294967296000000000ULL" " is out of
timeval's range" && ((GstClockTime) (4294967296000000000ULL)) <
(((GstClockTime) (G_MAXUINT32 - 1U)) * GST_SECOND))
  assertion failed: ("Value of time " "tmp" " is out of timeval's range" &&
((GstClockTime) (tmp)) < (((GstClockTime) (G_MAXUINT32 - 1U)) * GST_SECOND))

GST_TIME_TO_TIMEVAL() is only used once in gstreamer,
gst-plugins-* and gst-* -- the public function gst_poll_wait().
In this function GST_CLOCK_TIME_NONE is handled specially but
other out of range values are passed directly go
GST_TIME_TO_TIMEVAL(). To make sure I haven't broken anything
I have run make check on git HEAD of gstreamer, gst-plugins-*
and gst-* and there are as many failing tests before as there
are after my patch. ;)

-- 
Configure bugmail: https://bugzilla.gnome.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the gstreamer-bugs mailing list