mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
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.
This commit is contained in:
parent
00ed93780d
commit
9b7da39b68
2 changed files with 25 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue