getbits.cpp 851 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "rar.hpp"
  2. BitInput::BitInput()
  3. {
  4. // getbits attempts to read data from InAddr, InAddr+1, InAddr+2 positions.
  5. // So let's allocate two additional bytes for situation, when we need to
  6. // read only 1 byte from the last position of buffer and avoid a crash
  7. // from access to next 2 bytes, which contents we do not need.
  8. size_t BufSize=MAX_SIZE+2;
  9. InBuf=new byte[BufSize];
  10. // Ensure that we get predictable results when accessing bytes in area
  11. // not filled with read data.
  12. memset(InBuf,0,BufSize);
  13. }
  14. BitInput::~BitInput()
  15. {
  16. delete[] InBuf;
  17. }
  18. void BitInput::faddbits(uint Bits)
  19. {
  20. // Function wrapped version of inline addbits to save code size.
  21. addbits(Bits);
  22. }
  23. uint BitInput::fgetbits()
  24. {
  25. // Function wrapped version of inline getbits to save code size.
  26. return(getbits());
  27. }