Commit e3c80953 authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

libFLAC/bitwriter.c: Fix undefined behaviour

Improve folding of signed to unsgned to avoid UB.
parent b18d8d50
...@@ -520,7 +520,9 @@ FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FL ...@@ -520,7 +520,9 @@ FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FL
while(nvals) { while(nvals) {
/* fold signed to unsigned; actual formula is: negative(v)? -2v-1 : 2v */ /* fold signed to unsigned; actual formula is: negative(v)? -2v-1 : 2v */
uval = (*vals<<1) ^ (*vals>>31); uval = *vals;
uval <<= 1;
uval ^= (*vals>>31);
msbits = uval >> parameter; msbits = uval >> parameter;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment