GNOME Bugzilla – Bug 533075
gst_rtp_buffer_compare_seqnum doesn't do what it says
Last modified: 2008-05-14 13:43:10 UTC
A recent comment change for gst_rtp_buffer_compare_seqnum says that it will return the difference in sequence numbers. In its current implementation, it does not. e.g. gst_rtp_buffer_compare_seqnum(0xFFFF, 0) returns 65535, not -1 as desired. A much easier approach is to cast the difference into a signed gint16, then into an gint (the function's return type), then the compiler and OS takes care of the wraparound and sign extension for you. e.g. gint gst_rtp_buffer_compare_seqnum (guint16 seqnum1, guint16 seqnum2) { return (gint16)(seqnum2-seqnum1); } This survives this simple test below (apologies for not making it an attachment), where as the original function (revision 1.22 of gstrtpbuffer.c) does not. void test() { int i, diff; uint16 a, b; for (diff = -100; diff < 100; diff++) { a = 0; for (i = 0; i < 0x20000; i++) { b = a + diff; assert(gst_rtp_buffer_compare_seqnum(a, b) == diff); a++; } } }
Patch by: Bernard B <b-gnome at largestprime dot net> * gst-libs/gst/rtp/gstrtpbuffer.c: (gst_rtp_buffer_compare_seqnum): Fix seqnum compare function for bordercase values and fix the docs again. Fixes #533075. * tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite): Add a testcase for seqnum compare function.