diff options
author | v0lt <v0lt@rambler.ru> | 2013-02-02 01:25:12 +0400 |
---|---|---|
committer | v0lt <v0lt@rambler.ru> | 2013-02-02 01:25:12 +0400 |
commit | 31ee5a3ce828836239fdd3f812bd7fee2f8c1377 (patch) | |
tree | c59a5f4e884bc9faa39841d052e06d93297bbf33 /src/DSUtil/GolombBuffer.cpp | |
parent | 68ffc9799616f7ec6256cb1ff99a7377474adab7 (diff) |
Fixed potentially incorrect work of function CGolombBuffer::BitRead.
Diffstat (limited to 'src/DSUtil/GolombBuffer.cpp')
-rw-r--r-- | src/DSUtil/GolombBuffer.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/DSUtil/GolombBuffer.cpp b/src/DSUtil/GolombBuffer.cpp index e2c7a4555..057ede638 100644 --- a/src/DSUtil/GolombBuffer.cpp +++ b/src/DSUtil/GolombBuffer.cpp @@ -49,7 +49,14 @@ UINT64 CGolombBuffer::BitRead(int nBits, bool fPeek) int bitlen = m_bitlen - nBits;
- UINT64 ret = (m_bitbuff >> bitlen) & ((1ui64 << nBits) - 1);
+ UINT64 ret;
+ // The shift to 64 bits can give incorrect results.
+ // "The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand."
+ if (nBits == 64) {
+ ret = m_bitbuff;
+ } else {
+ ret = (m_bitbuff >> bitlen) & ((1ui64 << nBits) - 1);
+ }
if (!fPeek) {
m_bitbuff &= ((1ui64 << bitlen) - 1);
|