aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dec/bit_reader.h1
-rw-r--r--enc/encode.cc2
-rw-r--r--enc/encode.h2
-rw-r--r--enc/hash.h2
-rw-r--r--enc/ringbuffer.h18
-rw-r--r--enc/write_bits.h4
6 files changed, 15 insertions, 14 deletions
diff --git a/dec/bit_reader.h b/dec/bit_reader.h
index f390348..468afe1 100644
--- a/dec/bit_reader.h
+++ b/dec/bit_reader.h
@@ -18,6 +18,7 @@
#ifndef BROTLI_DEC_BIT_READER_H_
#define BROTLI_DEC_BIT_READER_H_
+#include <stdio.h>
#include <string.h>
#include "./port.h"
#include "./types.h"
diff --git a/enc/encode.cc b/enc/encode.cc
index f46a1c9..e77ee4d 100644
--- a/enc/encode.cc
+++ b/enc/encode.cc
@@ -546,8 +546,6 @@ bool BrotliCompressor::WriteMetadata(const size_t input_size,
if (input_size == 0) {
WriteBits(2, 0, &storage_ix, encoded_buffer);
*encoded_size = (storage_ix + 7) >> 3;
- } else if (input_size > (1 << 24)) {
- return false;
} else {
int nbits = Log2Floor(static_cast<uint32_t>(input_size) - 1) + 1;
int nbytes = (nbits + 7) / 8;
diff --git a/enc/encode.h b/enc/encode.h
index d73e6d4..13d2e5c 100644
--- a/enc/encode.h
+++ b/enc/encode.h
@@ -79,7 +79,7 @@ class BrotliCompressor {
~BrotliCompressor();
// The maximum input size that can be processed at once.
- size_t input_block_size() const { return 1 << params_.lgblock; }
+ size_t input_block_size() const { return size_t(1) << params_.lgblock; }
// Encodes the data in input_buffer as a meta-block and writes it to
// encoded_buffer (*encoded_size should be set to the size of
diff --git a/enc/hash.h b/enc/hash.h
index 4e9c896..9c31cae 100644
--- a/enc/hash.h
+++ b/enc/hash.h
@@ -510,7 +510,7 @@ class HashLongestMatch {
if (len > kMaxZopfliLen) {
matches = orig_matches;
}
- *matches++ = BackwardMatch(backward, len);
+ *matches++ = BackwardMatch(static_cast<int>(backward), len);
}
}
const uint32_t key = HashBytes(&data[cur_ix_masked]);
diff --git a/enc/ringbuffer.h b/enc/ringbuffer.h
index a357c41..6111e25 100644
--- a/enc/ringbuffer.h
+++ b/enc/ringbuffer.h
@@ -32,11 +32,12 @@ class RingBuffer {
public:
RingBuffer(int window_bits, int tail_bits)
: window_bits_(window_bits),
- mask_((1 << window_bits) - 1),
- tail_size_(1 << tail_bits),
+ size_((size_t(1) << window_bits)),
+ mask_((size_t(1) << window_bits) - 1),
+ tail_size_(size_t(1) << tail_bits),
pos_(0) {
static const int kSlackForEightByteHashingEverywhere = 7;
- const size_t buflen = (1 << window_bits_) + tail_size_;
+ const size_t buflen = size_ + tail_size_;
buffer_ = new uint8_t[buflen + kSlackForEightByteHashingEverywhere];
for (int i = 0; i < kSlackForEightByteHashingEverywhere; ++i) {
buffer_[buflen + i] = 0;
@@ -52,17 +53,17 @@ class RingBuffer {
// The length of the writes is limited so that we do not need to worry
// about a write
WriteTail(bytes, n);
- if (PREDICT_TRUE(masked_pos + n <= (1U << window_bits_))) {
+ if (PREDICT_TRUE(masked_pos + n <= size_)) {
// A single write fits.
memcpy(&buffer_[masked_pos], bytes, n);
} else {
// Split into two writes.
// Copy into the end of the buffer, including the tail buffer.
memcpy(&buffer_[masked_pos], bytes,
- std::min(n, ((1 << window_bits_) + tail_size_) - masked_pos));
+ std::min(n, (size_ + tail_size_) - masked_pos));
// Copy into the beginning of the buffer
- memcpy(&buffer_[0], bytes + ((1 << window_bits_) - masked_pos),
- n - ((1 << window_bits_) - masked_pos));
+ memcpy(&buffer_[0], bytes + (size_ - masked_pos),
+ n - (size_ - masked_pos));
}
pos_ += n;
}
@@ -85,13 +86,14 @@ class RingBuffer {
const size_t masked_pos = pos_ & mask_;
if (PREDICT_FALSE(masked_pos < tail_size_)) {
// Just fill the tail buffer with the beginning data.
- const size_t p = (1 << window_bits_) + masked_pos;
+ const size_t p = size_ + masked_pos;
memcpy(&buffer_[p], bytes, std::min(n, tail_size_ - masked_pos));
}
}
// Size of the ringbuffer is (1 << window_bits) + tail_size_.
const int window_bits_;
+ const size_t size_;
const size_t mask_;
const size_t tail_size_;
diff --git a/enc/write_bits.h b/enc/write_bits.h
index 09e98a1..aa58dd9 100644
--- a/enc/write_bits.h
+++ b/enc/write_bits.h
@@ -66,12 +66,12 @@ inline void WriteBits(int n_bits,
uint8_t *array_pos = &array[*pos >> 3];
const int bits_reserved_in_first_byte = (*pos & 7);
bits <<= bits_reserved_in_first_byte;
- *array_pos++ |= bits;
+ *array_pos++ |= static_cast<uint8_t>(bits);
for (int bits_left_to_write = n_bits - 8 + bits_reserved_in_first_byte;
bits_left_to_write >= 1;
bits_left_to_write -= 8) {
bits >>= 8;
- *array_pos++ = bits;
+ *array_pos++ = static_cast<uint8_t>(bits);
}
*array_pos = 0;
*pos += n_bits;