diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2014-06-19 09:23:56 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2014-06-19 09:33:54 +0200 |
commit | 9b7da39b68544513d1483d19cf9e74eb97aba4ca (patch) | |
tree | 2c0032968db96d703784f80107e31f0fb091d3c7 | |
parent | 00ed93780dba49ca2d9208e1b2d734617f691ff7 (diff) |
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.
-rw-r--r-- | gst/gstvalue.c | 32 | ||||
-rw-r--r-- | tests/check/gst/gstvalue.c | 7 |
2 files changed, 25 insertions, 14 deletions
diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 85d3a11c9..ca6ce7d99 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 b4cd2d2b1..9a0df4270 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); |