stb_image: Avoid shift of signed values in extend_receive
Use an equivalent formulation that has sgn=0 or 1, not 0 or -1. This avoids right-shifting signed values, at least in this place. Fixes issue #1061.
This commit is contained in:
parent
6d857933d5
commit
43b32c7bab
@ -2102,12 +2102,12 @@ stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n)
|
|||||||
int sgn;
|
int sgn;
|
||||||
if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
|
if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
|
||||||
|
|
||||||
sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB
|
sgn = j->code_buffer >> 31; // sign bit always in MSB; 0 if MSB clear (positive), 1 if MSB set (negative)
|
||||||
k = stbi_lrot(j->code_buffer, n);
|
k = stbi_lrot(j->code_buffer, n);
|
||||||
j->code_buffer = k & ~stbi__bmask[n];
|
j->code_buffer = k & ~stbi__bmask[n];
|
||||||
k &= stbi__bmask[n];
|
k &= stbi__bmask[n];
|
||||||
j->code_bits -= n;
|
j->code_bits -= n;
|
||||||
return k + (stbi__jbias[n] & ~sgn);
|
return k + (stbi__jbias[n] & (sgn - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get some unsigned bits
|
// get some unsigned bits
|
||||||
|
Loading…
Reference in New Issue
Block a user