mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
gstutils: Fix violations of strict-aliasing rules in gst_util_uint64_scale()
This commit is contained in:
parent
3d359729af
commit
6a84be95be
1 changed files with 15 additions and 11 deletions
|
@ -311,18 +311,22 @@ gst_util_div128_64 (guint64 c1, guint64 c0, guint64 denom, guint64 * remainder)
|
|||
*/
|
||||
|
||||
guint64 quotient = 0;
|
||||
GstUInt64 _c1;
|
||||
|
||||
_c1.ll = c1;
|
||||
|
||||
while (_c1.ll) {
|
||||
GstUInt64 _a;
|
||||
|
||||
while (c1) {
|
||||
guint64 a;
|
||||
/* add c1 * (2^64 // d) to quotient, store 2^64 % d in a */
|
||||
quotient += c1 * gst_util_two_to_the_64_over_d (denom, &a);
|
||||
quotient += _c1.ll * gst_util_two_to_the_64_over_d (denom, &_a.ll);
|
||||
/* store the high and low words of c1 * (2^64 % d) in c1 and a
|
||||
* respectively */
|
||||
gst_util_uint64_mul_uint64 ((GstUInt64 *) & c1, (GstUInt64 *) & a, c1, a);
|
||||
gst_util_uint64_mul_uint64 (&_c1, &_a, _c1.ll, _a.ll);
|
||||
/* add a to c0, with a carry into c1 if the result rolls over */
|
||||
if (G_MAXUINT64 - c0 < a)
|
||||
c1++;
|
||||
c0 += a;
|
||||
if (G_MAXUINT64 - c0 < _a.ll)
|
||||
_c1.ll++;
|
||||
c0 += _a.ll;
|
||||
}
|
||||
|
||||
/* c1 is 0. use regular integer arithmetic with c0 to complete result */
|
||||
|
@ -361,17 +365,17 @@ static guint64
|
|||
gst_util_uint64_scale_uint64_unchecked (guint64 val, guint64 num,
|
||||
guint64 denom, guint64 * remainder)
|
||||
{
|
||||
guint64 c1, c0;
|
||||
GstUInt64 c1, c0;
|
||||
|
||||
/* compute 128-bit numerator product */
|
||||
gst_util_uint64_mul_uint64 ((GstUInt64 *) & c1, (GstUInt64 *) & c0, val, num);
|
||||
gst_util_uint64_mul_uint64 (&c1, &c0, val, num);
|
||||
|
||||
/* high word as big as or bigger than denom --> overflow */
|
||||
if (G_UNLIKELY (c1 >= denom))
|
||||
if (G_UNLIKELY (c1.ll >= denom))
|
||||
return G_MAXUINT64;
|
||||
|
||||
/* compute quotient, fits in 64 bits */
|
||||
return gst_util_div128_64 (c1, c0, denom, remainder);
|
||||
return gst_util_div128_64 (c1.ll, c0.ll, denom, remainder);
|
||||
}
|
||||
|
||||
static inline guint64
|
||||
|
|
Loading…
Reference in a new issue