1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibAudio: Fix 32-bit/64-bit mixup in FLAC sign extend

The bit magic for two's complement sign extension was only sign
extending to 32-bit signed. This issue was exposed by the last commit,
where now we actually use the 64-bit return value.
This commit is contained in:
kleines Filmröllchen 2023-06-26 15:26:00 +02:00 committed by Jelle Raaijmakers
parent 59c7ce3d54
commit 952c633a65

View file

@ -768,7 +768,7 @@ ErrorOr<Vector<i64>, LoaderError> FlacLoaderPlugin::decode_custom_lpc(FlacSubfra
// read coefficients
for (auto i = 0; i < subframe.order; ++i) {
u64 raw_coefficient = LOADER_TRY(bit_input.read_bits<u64>(lpc_precision));
i64 coefficient = static_cast<i64>(sign_extend(raw_coefficient, lpc_precision));
i64 coefficient = sign_extend(raw_coefficient, lpc_precision);
coefficients.unchecked_append(coefficient);
}
@ -970,7 +970,7 @@ i64 sign_extend(u32 n, u8 size)
{
// negative
if ((n & (1 << (size - 1))) > 0) {
return static_cast<i64>(n | (0xffffffff << size));
return static_cast<i64>(n | (0xffffffffffffffffLL << size));
}
// positive
return n;