| 32 | } |
| 33 | |
| 34 | Block::Block(const BlockContents& contents) |
| 35 | : data_(contents.data.data()), |
| 36 | size_(contents.data.size()), |
| 37 | owned_(contents.heap_allocated) { |
| 38 | if (size_ < sizeof(uint32)) { |
| 39 | size_ = 0; // Error marker |
| 40 | } else { |
| 41 | size_t max_restarts_allowed = (size_ - sizeof(uint32)) / sizeof(uint32); |
| 42 | if (NumRestarts() > max_restarts_allowed) { |
| 43 | // The size is too small for NumRestarts() |
| 44 | size_ = 0; |
| 45 | } else { |
| 46 | restart_offset_ = size_ - (1 + NumRestarts()) * sizeof(uint32); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | Block::~Block() { |
| 52 | if (owned_) { |