From: Sebastian Dröge Date: Thu, 19 Jun 2014 07:23:56 +0000 (+0200) Subject: value: Make sure to cast int range values to guints before storing them X-Git-Tag: 1.3.3~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b7da39b68544513d1483d19cf9e74eb97aba4ca;p=platform%2Fupstream%2Fgstreamer.git value: Make sure to cast int range values to guints before storing them Otherwise negative values will sets all of the 64 bits due to two's complement's definition of negative values. Also add a test for negative int ranges. --- diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 85d3a11c91..ca6ce7d997 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -980,8 +980,8 @@ gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step) g_return_if_fail (start % step == 0); g_return_if_fail (end % step == 0); - sstart = (guint64) (start / step); - sstop = (guint64) (end / step); + sstart = (guint) (start / step); + sstop = (guint) (end / step); value->data[0].v_uint64 = (sstart << 32) | sstop; value->data[1].v_int = step; } @@ -3331,8 +3331,9 @@ gst_value_union_int_int_range (GValue * dest, const GValue * src1, /* check if it extends the range */ if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) { if (dest) { - guint64 new_min = (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2); - guint64 new_max = INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2); + guint64 new_min = + (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)); + guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2)); gst_value_init_and_copy (dest, src2); dest->data[0].v_uint64 = (new_min << 32) | (new_max); @@ -3341,8 +3342,9 @@ gst_value_union_int_int_range (GValue * dest, const GValue * src1, } if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) { if (dest) { - guint64 new_min = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2); - guint64 new_max = (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2); + guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2)); + guint64 new_max = + (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)); gst_value_init_and_copy (dest, src2); dest->data[0].v_uint64 = (new_min << 32) | (new_max); @@ -3411,10 +3413,11 @@ gst_value_union_int_range_int_range (GValue * dest, const GValue * src1, if (scalar == (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) { if (dest) { - guint64 new_min = - (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value); - guint64 new_max = - INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value); + guint64 new_min = (guint) + ((INT_RANGE_MIN (range_value) - + 1) * INT_RANGE_STEP (range_value)); + guint64 new_max = (guint) + (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value)); gst_value_init_and_copy (dest, range_value); dest->data[0].v_uint64 = (new_min << 32) | (new_max); @@ -3423,10 +3426,11 @@ gst_value_union_int_range_int_range (GValue * dest, const GValue * src1, } else if (scalar == (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) { if (dest) { - guint64 new_min = - INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value); - guint64 new_max = - (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value); + guint64 new_min = (guint) + (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value)); + guint64 new_max = (guint) + ((INT_RANGE_MAX (range_value) + + 1) * INT_RANGE_STEP (range_value)); gst_value_init_and_copy (dest, range_value); dest->data[0].v_uint64 = (new_min << 32) | (new_max); } diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c index b4cd2d2b18..9a0df42709 100644 --- a/tests/check/gst/gstvalue.c +++ b/tests/check/gst/gstvalue.c @@ -2505,6 +2505,13 @@ GST_START_TEST (test_int_range) g_value_unset (&dest); fail_unless (gst_value_intersect (&dest, &range, &range2) == FALSE); + gst_value_set_int_range (&range, -7, -6); + fail_unless_equals_int (gst_value_get_int_range_min (&range), -7); + fail_unless_equals_int (gst_value_get_int_range_max (&range), -6); + gst_value_set_int_range (&range, -7, 7); + fail_unless_equals_int (gst_value_get_int_range_min (&range), -7); + fail_unless_equals_int (gst_value_get_int_range_max (&range), 7); + g_value_unset (&start); g_value_unset (&end); g_value_unset (&range);