mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:17 +00:00
audio: Clamp unsigned sample conversion
clip_*_uint32_t() returns 0 when v == 1.f because it computes the result as (IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF): - (v * ((mixeng_real)IN_MAX / 2.f)) + HALF == 0x100000000.f, which does not fit in uint32_t. - (v * ((mixeng_real)IN_MAX / 2.f)) == 0x80000000.f - ((mixeng_real)IN_MAX / 2.f) == 0x80000000.f - (mixeng_real)IN_MAX == 0x100000000.f because 0xffffffff cannot be represented exactly in float. - HALF == 0x7fffffff, which is implicitly converted to 0x80000000.f. Clamp the result to avoid the overflow. Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20260423-audio-v1-2-e1d6b65c76f9@rsg.ci.i.u-tokyo.ac.jp>
This commit is contained in:
committed by
Marc-André Lureau
parent
133c52f63e
commit
698399705c
@@ -65,7 +65,9 @@ static inline IN_T glue (clip_, ET) (mixeng_real v)
|
||||
#ifdef SIGNED
|
||||
return ENDIAN_CONVERT((IN_T)(v * (((mixeng_real)IN_MAX - IN_MIN) / 2.f)));
|
||||
#else
|
||||
return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF));
|
||||
return ENDIAN_CONVERT(MIN((int64_t)((v * ((mixeng_real)IN_MAX / 2.f)) +
|
||||
HALF),
|
||||
IN_MAX));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user