1 #include "rar.hpp"
2 
BitInput(bool AllocBuffer)3 BitInput::BitInput(bool AllocBuffer)
4 {
5   ExternalBuffer=false;
6   if (AllocBuffer)
7   {
8     // getbits32 attempts to read data from InAddr, ... InAddr+3 positions.
9     // So let's allocate 3 additional bytes for situation, when we need to
10     // read only 1 byte from the last position of buffer and avoid a crash
11     // from access to next 3 bytes, which contents we do not need.
12     size_t BufSize=MAX_SIZE+3;
13     InBuf=new byte[BufSize];
14 
15     // Ensure that we get predictable results when accessing bytes in area
16     // not filled with read data.
17     memset(InBuf,0,BufSize);
18   }
19   else
20     InBuf=NULL;
21 }
22 
23 
~BitInput()24 BitInput::~BitInput()
25 {
26   if (!ExternalBuffer)
27     delete[] InBuf;
28 }
29 
30 
faddbits(uint Bits)31 void BitInput::faddbits(uint Bits)
32 {
33   // Function wrapped version of inline addbits to save code size.
34   addbits(Bits);
35 }
36 
37 
fgetbits()38 uint BitInput::fgetbits()
39 {
40   // Function wrapped version of inline getbits to save code size.
41   return getbits();
42 }
43 
44 
SetExternalBuffer(byte * Buf)45 void BitInput::SetExternalBuffer(byte *Buf)
46 {
47   if (InBuf!=NULL && !ExternalBuffer)
48     delete[] InBuf;
49   InBuf=Buf;
50   ExternalBuffer=true;
51 }
52 
53