Skip to content

Commit 5c1ee60

Browse files
committed
fix some usize->u64 ambiguities
1 parent c35215d commit 5c1ee60

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "brotli"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
authors = ["Daniel Reiter Horn <[email protected]>", "The Brotli Authors"]
55
description = "A brotli decompressor that with an interface avoiding the rust stdlib. This makes it suitable for embedded devices and kernels. It is designed with a pluggable allocator so that the standard lib's allocator may be employed. The default build also includes a stdlib allocator and stream interface. Disable this with --features=no-stdlib. All included code is safe."
66
license = "BSD-3-Clause/MIT"

src/enc/brotli_bit_stream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ pub fn BrotliStoreMetaBlock<'a,
23662366
if cmd.cmd_prefix_ as (i32) >= 128i32 {
23672367
let dist_code: usize = cmd.dist_prefix_ as (usize);
23682368
let distnumextra: u32 = cmd.dist_extra_ >> 24i32;
2369-
let distextra: usize = (cmd.dist_extra_ & 0xffffffu32) as (usize);
2369+
let distextra: u64 = (cmd.dist_extra_ & 0xffffffu32) as (u64);
23702370
if (*mb).distance_context_map_size == 0usize {
23712371
StoreSymbol(&mut distance_enc, dist_code, storage_ix, storage);
23722372
} else {
@@ -2379,7 +2379,7 @@ pub fn BrotliStoreMetaBlock<'a,
23792379
storage,
23802380
2usize);
23812381
}
2382-
BrotliWriteBits(distnumextra as (u8), distextra as u64, storage_ix, storage);
2382+
BrotliWriteBits(distnumextra as (u8), distextra, storage_ix, storage);
23832383
}
23842384
}
23852385
}
@@ -2467,7 +2467,7 @@ fn StoreDataWithHuffmanCodes(input: &[u8],
24672467
if CommandCopyLen(&cmd) != 0 && (cmd.cmd_prefix_ as (i32) >= 128i32) {
24682468
let dist_code: usize = cmd.dist_prefix_ as (usize);
24692469
let distnumextra: u32 = cmd.dist_extra_ >> 24i32;
2470-
let distextra: u32 = cmd.dist_extra_ & 0xffffffu32;
2470+
let distextra: u32 = cmd.dist_extra_ & 0xffffff;
24712471
BrotliWriteBits(dist_depth[(dist_code as (usize))] as (u8),
24722472
dist_bits[(dist_code as (usize))] as (u64),
24732473
storage_ix,

src/enc/encode.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ pub struct BrotliEncoderStateStruct<AllocU8: alloc::Allocator<u8>,
167167
pub m32: AllocU32,
168168
pub mc: AllocCommand,
169169
pub hasher_: UnionHasher<AllocU16, AllocU32>,
170-
pub input_pos_: usize,
170+
pub input_pos_: u64,
171171
pub ringbuffer_: RingBuffer<AllocU8>,
172172
pub cmd_alloc_size_: usize,
173173
pub commands_: AllocCommand::AllocatedMemory, // not sure about this one
174174
pub num_commands_: usize,
175175
pub num_literals_: usize,
176176
pub last_insert_len_: usize,
177-
pub last_flush_pos_: usize,
178-
pub last_processed_pos_: usize,
177+
pub last_flush_pos_: u64,
178+
pub last_processed_pos_: u64,
179179
pub dist_cache_: [i32; 16],
180180
pub saved_dist_cache_: [i32; kNumDistanceCacheEntries],
181181
pub last_byte_: u8,
@@ -317,12 +317,12 @@ pub fn BrotliEncoderCreateInstance<AllocU8: alloc::Allocator<u8>,
317317
let cache: [i32; 16] = [4, 11, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
318318
BrotliEncoderStateStruct::<AllocU8, AllocU16, AllocU32, AllocI32, AllocCommand> {
319319
params: BrotliEncoderInitParams(),
320-
input_pos_: 0usize,
320+
input_pos_: 0,
321321
num_commands_: 0usize,
322322
num_literals_: 0usize,
323323
last_insert_len_: 0usize,
324-
last_flush_pos_: 0usize,
325-
last_processed_pos_: 0usize,
324+
last_flush_pos_: 0,
325+
last_processed_pos_: 0,
326326
prev_byte_: 0i32 as (u8),
327327
prev_byte2_: 0i32 as (u8),
328328
storage_size_: 0usize,
@@ -979,7 +979,7 @@ fn CopyInputToRingBuffer<AllocU8: alloc::Allocator<u8>,
979979
if !(0i32 == 0) {
980980
return;
981981
}
982-
(*s).input_pos_ = (*s).input_pos_.wrapping_add(input_size);
982+
(*s).input_pos_ = (*s).input_pos_.wrapping_add(input_size as u64);
983983
if (s.ringbuffer_).pos_ <= (s.ringbuffer_).mask_ {
984984
let start = ((s.ringbuffer_).buffer_index.wrapping_add((s.ringbuffer_).pos_ as (usize)) as
985985
(usize));
@@ -1292,9 +1292,9 @@ pub fn BrotliEncoderSetCustomDictionary<AllocU8: alloc::Allocator<u8>,
12921292
dict_size = max_dict_size;
12931293
}
12941294
CopyInputToRingBuffer(s, dict_size, dict);
1295-
(*s).last_flush_pos_ = dict_size;
1296-
(*s).last_processed_pos_ = dict_size;
1297-
if dict_size > 0usize {
1295+
(*s).last_flush_pos_ = dict_size as u64;
1296+
(*s).last_processed_pos_ = dict_size as u64;
1297+
if dict_size > 0 {
12981298
(*s).prev_byte_ = dict[(dict_size.wrapping_sub(1usize) as (usize))];
12991299
}
13001300
if dict_size > 1usize {
@@ -1380,7 +1380,7 @@ fn InitInsertCommand(xself: &mut Command, insertlen: usize) {
13801380

13811381
fn ShouldCompress(data: &[u8],
13821382
mask: usize,
1383-
last_flush_pos: usize,
1383+
last_flush_pos: u64,
13841384
bytes: usize,
13851385
num_literals: usize,
13861386
num_commands: usize)
@@ -2050,7 +2050,7 @@ fn UnprocessedInputSize<AllocU8: alloc::Allocator<u8>,
20502050
AllocU32: alloc::Allocator<u32>,
20512051
AllocI32: alloc::Allocator<i32>,
20522052
AllocCommand: alloc::Allocator<Command>>(
2053-
s: &mut BrotliEncoderStateStruct<AllocU8, AllocU16, AllocU32, AllocI32, AllocCommand>) -> usize {
2053+
s: &mut BrotliEncoderStateStruct<AllocU8, AllocU16, AllocU32, AllocI32, AllocCommand>) -> u64 {
20542054
(*s).input_pos_.wrapping_sub((*s).last_processed_pos_)
20552055
}
20562056

@@ -2061,12 +2061,12 @@ fn UpdateSizeHint<AllocU8: alloc::Allocator<u8>,
20612061
AllocCommand: alloc::Allocator<Command>>(s: &mut BrotliEncoderStateStruct<AllocU8, AllocU16, AllocU32, AllocI32, AllocCommand>,
20622062
available_in: usize) {
20632063
if (*s).params.size_hint == 0usize {
2064-
let delta: usize = UnprocessedInputSize(s);
2065-
let tail: usize = available_in;
2064+
let delta: u64 = UnprocessedInputSize(s);
2065+
let tail: u64 = available_in as u64;
20662066
let limit: u32 = 1u32 << 30i32;
20672067
let total: u32;
2068-
if delta >= limit as (usize) || tail >= limit as (usize) ||
2069-
delta.wrapping_add(tail) >= limit as (usize) {
2068+
if delta >= u64::from(limit) || tail >= u64::from(limit) ||
2069+
delta.wrapping_add(tail) >= u64::from(limit) {
20702070
total = limit;
20712071
} else {
20722072
total = delta.wrapping_add(tail) as (u32);
@@ -2076,12 +2076,12 @@ fn UpdateSizeHint<AllocU8: alloc::Allocator<u8>,
20762076
}
20772077

20782078

2079-
fn WrapPosition(position: usize) -> u32 {
2079+
fn WrapPosition(position: u64) -> u32 {
20802080
let mut result: u32 = position as (u32);
2081-
let gb: usize = position >> 30i32;
2082-
if gb > 2usize {
2081+
let gb: u64 = position >> 30i32;
2082+
if gb > 2 {
20832083
result = result & (1u32 << 30i32).wrapping_sub(1u32) |
2084-
((gb.wrapping_sub(1usize) & 1usize) as (u32)).wrapping_add(1u32) << 30i32;
2084+
((gb.wrapping_sub(1) & 1) as (u32)).wrapping_add(1u32) << 30i32;
20852085
}
20862086
result
20872087
}
@@ -2442,7 +2442,7 @@ fn WriteMetaBlockInternal<AllocU8: alloc::Allocator<u8>,
24422442
mht: &mut AllocHT,
24432443
data: &[u8],
24442444
mask: usize,
2445-
last_flush_pos: usize,
2445+
last_flush_pos: u64,
24462446
bytes: usize,
24472447
is_last: i32,
24482448
params: &BrotliEncoderParams,
@@ -2670,7 +2670,7 @@ fn EncodeData<AllocU8: alloc::Allocator<u8>,
26702670
callback: &mut MetablockCallback
26712671
// mut output: &'a mut &'a mut [u8]
26722672
) -> i32 where MetablockCallback: FnMut(&[interface::Command<InputReference>]){
2673-
let delta: usize = UnprocessedInputSize(s);
2673+
let delta: u64 = UnprocessedInputSize(s);
26742674
let bytes: u32 = delta as (u32);
26752675
let wrapped_last_processed_pos: u32 = WrapPosition((*s).last_processed_pos_);
26762676
let mask: u32;
@@ -2685,7 +2685,7 @@ fn EncodeData<AllocU8: alloc::Allocator<u8>,
26852685
if is_last != 0 {
26862686
(*s).is_last_block_emitted_ = 1i32;
26872687
}
2688-
if delta > InputBlockSize(s) {
2688+
if delta > InputBlockSize(s) as u64 {
26892689
return 0i32;
26902690
}
26912691
if (*s).params.quality == 1i32 && (*s).command_buf_.slice().len() == 0 {
@@ -2699,7 +2699,7 @@ fn EncodeData<AllocU8: alloc::Allocator<u8>,
26992699
let mut table_size: usize = 0;
27002700
{
27012701
let table: &mut [i32];
2702-
if delta == 0usize && (is_last == 0) {
2702+
if delta == 0 && (is_last == 0) {
27032703
*out_size = 0usize;
27042704
return 1i32;
27052705
}
@@ -2813,7 +2813,7 @@ fn EncodeData<AllocU8: alloc::Allocator<u8>,
28132813
let max_length: usize = MaxMetablockSize(&mut (*s).params);
28142814
let max_literals: usize = max_length.wrapping_div(8usize);
28152815
let max_commands: usize = max_length.wrapping_div(8usize);
2816-
let processed_bytes: usize = (*s).input_pos_.wrapping_sub((*s).last_flush_pos_);
2816+
let processed_bytes: usize = (*s).input_pos_.wrapping_sub((*s).last_flush_pos_) as usize;
28172817
let next_input_fits_metablock: i32 = if !!(processed_bytes.wrapping_add(InputBlockSize(s)) <=
28182818
max_length) {
28192819
1i32
@@ -2886,12 +2886,12 @@ fn EncodeData<AllocU8: alloc::Allocator<u8>,
28862886
HasherReset(&mut (*s).hasher_);
28872887
}
28882888
let data = &(*s).ringbuffer_.data_mo.slice()[(*s).ringbuffer_.buffer_index as usize..];
2889-
if (*s).last_flush_pos_ > 0usize {
2889+
if (*s).last_flush_pos_ > 0 {
28902890
(*s).prev_byte_ = data[((((*s).last_flush_pos_ as (u32)).wrapping_sub(1u32) & mask) as
28912891
(usize))];
28922892
}
2893-
if (*s).last_flush_pos_ > 1usize {
2894-
(*s).prev_byte2_ = data[(((*s).last_flush_pos_.wrapping_sub(2usize) as (u32) & mask) as
2893+
if (*s).last_flush_pos_ > 1 {
2894+
(*s).prev_byte2_ = data[(((*s).last_flush_pos_.wrapping_sub(2) as (u32) & mask) as
28952895
(usize))];
28962896
}
28972897
(*s).num_commands_ = 0usize;
@@ -3246,12 +3246,12 @@ fn RemainingInputBlockSize<AllocU8: alloc::Allocator<u8>,
32463246
AllocU32: alloc::Allocator<u32>,
32473247
AllocI32: alloc::Allocator<i32>,
32483248
AllocCommand: alloc::Allocator<Command>>(s: &mut BrotliEncoderStateStruct<AllocU8, AllocU16, AllocU32, AllocI32, AllocCommand>) -> usize {
3249-
let delta: usize = UnprocessedInputSize(s);
3249+
let delta: u64 = UnprocessedInputSize(s);
32503250
let block_size: usize = InputBlockSize(s);
3251-
if delta >= block_size {
3251+
if delta >= block_size as u64 {
32523252
return 0usize;
32533253
}
3254-
block_size.wrapping_sub(delta)
3254+
(block_size as u64).wrapping_sub(delta) as usize
32553255
}
32563256

32573257
pub fn BrotliEncoderCompressStream<AllocU8: alloc::Allocator<u8>,

0 commit comments

Comments
 (0)