Skip to content

Commit b199365

Browse files
eustascopybara-github
authored andcommitted
Fix one-off in dcheck.
How to prove correctness: 1) when `position` is `0`, `max_length` is allowed to be `ringbuffer_size` 2) in other words: `position + max_length <= ringbuffer_size` 3) `ringbuffer_mask == ringbuffer_size - 1` 4) thus `position + max_length <= ringbuffer_size + 1` PiperOrigin-RevId: 836145553
1 parent 5151a22 commit b199365

8 files changed

+9
-9
lines changed

c/enc/backward_references_hq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static size_t UpdateNodes(
433433
const CompoundDictionary* addon = &params->dictionary.compound;
434434
size_t gap = addon->total_size;
435435

436-
BROTLI_DCHECK(cur_ix_masked + max_len <= ringbuffer_mask);
436+
BROTLI_DCHECK(cur_ix_masked + max_len <= ringbuffer_mask + 1);
437437

438438
EvaluateNode(block_start + stream_offset, pos, max_backward_limit, gap,
439439
starting_dist_cache, model, queue, nodes);

c/enc/hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static BROTLI_INLINE void FindCompoundDictionaryMatch(
545545
source = (const uint8_t*)BROTLI_UNALIGNED_LOAD_PTR((const uint8_t**)tail);
546546
}
547547

548-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
548+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
549549

550550
for (i = 0; i < 4; ++i) {
551551
const size_t distance = (size_t)distance_cache[i];
@@ -656,7 +656,7 @@ static BROTLI_INLINE size_t FindAllCompoundDictionaryMatches(
656656
source = (const uint8_t*)BROTLI_UNALIGNED_LOAD_PTR((const uint8_t**)tail);
657657
}
658658

659-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
659+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
660660

661661
while (item == 0) {
662662
size_t offset;

c/enc/hash_forgetful_chain_inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
213213
out->len = 0;
214214
out->len_code_delta = 0;
215215

216-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
216+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
217217

218218
/* Try last distance first. */
219219
for (i = 0; i < NUM_LAST_DISTANCES_TO_CHECK; ++i) {

c/enc/hash_longest_match64_inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
178178
out->len = 0;
179179
out->len_code_delta = 0;
180180

181-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
181+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
182182

183183
/* Try last distance first. */
184184
for (i = 0; i < (size_t)self->num_last_distances_to_check_; ++i) {

c/enc/hash_longest_match64_simd_inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
195195
out->len = 0;
196196
out->len_code_delta = 0;
197197

198-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
198+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
199199

200200
/* Try last distance first. */
201201
for (i = 0; i < (size_t)self->num_last_distances_to_check_; ++i) {

c/enc/hash_longest_match_inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
178178
out->len = 0;
179179
out->len_code_delta = 0;
180180

181-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
181+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
182182

183183
/* Try last distance first. */
184184
for (i = 0; i < (size_t)self->num_last_distances_to_check_; ++i) {

c/enc/hash_longest_match_quickly_inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
165165
size_t cached_backward = (size_t)distance_cache[0];
166166
size_t prev_ix = cur_ix - cached_backward;
167167

168-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
168+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
169169

170170
out->len_code_delta = 0;
171171
if (prev_ix < cur_ix) {

c/enc/hash_longest_match_simd_inc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
170170
out->len = 0;
171171
out->len_code_delta = 0;
172172

173-
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask);
173+
BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1);
174174

175175
/* Try last distance first. */
176176
for (i = 0; i < (size_t)self->num_last_distances_to_check_; ++i) {

0 commit comments

Comments
 (0)