Skip to content

Commit d583a8e

Browse files
committed
turn more asserts into debug asserts
1 parent d9299ba commit d583a8e

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

lib/common/entropy_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn FSE_readNCount_body(
8080
bitCount += 2 * repeats as i32;
8181

8282
/* Add the final repeat which isn't 0b11. */
83-
assert!((bitStream & 0b11) < 3);
83+
debug_assert!((bitStream & 0b11) < 3);
8484
charnum = charnum.wrapping_add(bitStream & 0b11);
8585
bitCount += 2;
8686

lib/decompress/huf_decompress.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -623,15 +623,15 @@ unsafe extern "C" fn HUF_decompress4X1_usingDTable_internal_fast_c_loop(
623623
let mut ip = args.ip;
624624
let mut op = args.op;
625625

626-
assert!(cfg!(target_endian = "little"));
627-
assert!(cfg!(target_pointer_width = "64"));
626+
debug_assert!(cfg!(target_endian = "little"));
627+
debug_assert!(cfg!(target_pointer_width = "64"));
628628

629629
'out: loop {
630630
/* Assert loop preconditions */
631631
if cfg!(debug_assertions) {
632632
for stream in 0..4 {
633-
assert!(op[stream] <= (if stream == 3 { oend } else { op[stream + 1] }));
634-
assert!(ip[stream] >= ilowest);
633+
debug_assert!(op[stream] <= (if stream == 3 { oend } else { op[stream + 1] }));
634+
debug_assert!(ip[stream] >= ilowest);
635635
}
636636
}
637637

@@ -664,7 +664,7 @@ unsafe extern "C" fn HUF_decompress4X1_usingDTable_internal_fast_c_loop(
664664

665665
if cfg!(debug_assertions) {
666666
for stream in 1..4 {
667-
assert!(ip[stream] >= ip[stream - 1]);
667+
debug_assert!(ip[stream] >= ip[stream - 1]);
668668
}
669669
}
670670

@@ -734,19 +734,19 @@ unsafe fn HUF_decompress4X1_usingDTable_internal_fast(
734734
Err(e) => return e.to_error_code(),
735735
};
736736

737-
assert!(args.ip[0] >= args.ilowest);
737+
debug_assert!(args.ip[0] >= args.ilowest);
738738
loopFn(&mut args);
739739

740740
// Our loop guarantees that ip[] >= ilowest and that we haven't overwritten any op[].
741741
let istart = src.as_ptr();
742-
assert!(args.ip[0] >= istart);
743-
assert!(args.ip[1] >= istart);
744-
assert!(args.ip[2] >= istart);
745-
assert!(args.ip[3] >= istart);
746-
assert!(args.op[3] <= oend);
742+
debug_assert!(args.ip[0] >= istart);
743+
debug_assert!(args.ip[1] >= istart);
744+
debug_assert!(args.ip[2] >= istart);
745+
debug_assert!(args.ip[3] >= istart);
746+
debug_assert!(args.op[3] <= oend);
747747

748-
assert_eq!(istart, args.ilowest);
749-
assert_eq!(istart.wrapping_add(6), args.iend[0]);
748+
debug_assert_eq!(istart, args.ilowest);
749+
debug_assert_eq!(istart.wrapping_add(6), args.iend[0]);
750750

751751
let segmentSize = dst.capacity().div_ceil(4);
752752
let mut segmentEnd = dst.as_mut_ptr_range().start;
@@ -1439,8 +1439,8 @@ unsafe extern "C" fn HUF_decompress4X2_usingDTable_internal_fast_c_loop(
14391439
/* Assert loop preconditions */
14401440
if cfg!(debug_assertions) {
14411441
for stream in 0..4 {
1442-
assert!(op[stream] <= oend[stream]);
1443-
assert!(ip[stream] >= ilowest);
1442+
debug_assert!(op[stream] <= oend[stream]);
1443+
debug_assert!(ip[stream] >= ilowest);
14441444
}
14451445
}
14461446

@@ -1489,7 +1489,7 @@ unsafe extern "C" fn HUF_decompress4X2_usingDTable_internal_fast_c_loop(
14891489
}
14901490

14911491
for stream in 1..4 {
1492-
assert!(ip[stream] >= ip[stream - 1]);
1492+
debug_assert!(ip[stream] >= ip[stream - 1]);
14931493
}
14941494

14951495
macro_rules! HUF_4X2_DECODE_SYMBOL {
@@ -1568,19 +1568,19 @@ unsafe fn HUF_decompress4X2_usingDTable_internal_fast(
15681568
Err(e) => return e.to_error_code(),
15691569
};
15701570

1571-
assert!(args.ip[0] >= args.ilowest);
1571+
debug_assert!(args.ip[0] >= args.ilowest);
15721572
loopFn(&mut args);
15731573

15741574
// note : op4 already verified within main loop.
15751575
let ilowest = src.as_ptr();
1576-
assert!(args.ip[0] >= ilowest);
1577-
assert!(args.ip[1] >= ilowest);
1578-
assert!(args.ip[2] >= ilowest);
1579-
assert!(args.ip[3] >= ilowest);
1580-
assert!(args.op[3] <= oend);
1576+
debug_assert!(args.ip[0] >= ilowest);
1577+
debug_assert!(args.ip[1] >= ilowest);
1578+
debug_assert!(args.ip[2] >= ilowest);
1579+
debug_assert!(args.ip[3] >= ilowest);
1580+
debug_assert!(args.op[3] <= oend);
15811581

1582-
assert_eq!(ilowest, args.ilowest);
1583-
assert_eq!(ilowest.add(6), args.iend[0]);
1582+
debug_assert_eq!(ilowest, args.ilowest);
1583+
debug_assert_eq!(ilowest.add(6), args.iend[0]);
15841584

15851585
let segmentSize = dst.capacity().div_ceil(4) as isize;
15861586
let mut segmentEnd = dst.as_mut_ptr();
@@ -2177,10 +2177,10 @@ impl<'a> Writer<'a> {
21772177
return None;
21782178
}
21792179

2180-
assert!(w1.end <= range.end);
2181-
assert!(w2.end <= range.end);
2182-
assert!(w3.end <= range.end);
2183-
assert!(w4.end <= range.end);
2180+
debug_assert!(w1.end <= range.end);
2181+
debug_assert!(w2.end <= range.end);
2182+
debug_assert!(w3.end <= range.end);
2183+
debug_assert!(w4.end <= range.end);
21842184

21852185
Some((w1, w2, w3, w4))
21862186
}

lib/decompress/zstd_decompress.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ fn decompression_margin(mut src: &[u8]) -> size_t {
13931393
margin += 3 * frameSizeInfo.nbBlocks;
13941394
maxBlockSize = Ord::max(maxBlockSize, zfh.blockSizeMax)
13951395
} else {
1396-
assert!(zfh.frameType == ZSTD_skippableFrame);
1396+
debug_assert!(zfh.frameType == ZSTD_skippableFrame);
13971397
/* Add the entire skippable frame size to our margin. */
13981398
margin += compressedSize;
13991399
}
@@ -3082,7 +3082,7 @@ pub unsafe extern "C" fn ZSTD_decompressStream(
30823082
.wrapping_sub(zds.lhSize)
30833083
.wrapping_add(ZSTD_blockHeaderSize);
30843084
}
3085-
assert!(!ip.is_null());
3085+
debug_assert!(!ip.is_null());
30863086
core::ptr::copy_nonoverlapping(
30873087
ip.cast::<u8>(),
30883088
zds.headerBuffer.as_mut_ptr().add(zds.lhSize),
@@ -3117,7 +3117,7 @@ pub unsafe extern "C" fn ZSTD_decompressStream(
31173117
if ERR_isError(decompressedSize) {
31183118
return decompressedSize;
31193119
}
3120-
assert!(!istart.is_null());
3120+
debug_assert!(!istart.is_null());
31213121
ip = istart.add(cSize);
31223122
op = if !op.is_null() {
31233123
op.add(decompressedSize)
@@ -3199,7 +3199,7 @@ pub unsafe extern "C" fn ZSTD_decompressStream(
31993199
let bufferSize = neededInBuffSize.wrapping_add(neededOutBuffSize);
32003200
if zds.staticSize != 0 {
32013201
// static DCtx
3202-
assert!(zds.staticSize >= size_of::<ZSTD_DCtx>()); // controlled at init
3202+
debug_assert!(zds.staticSize >= size_of::<ZSTD_DCtx>()); // controlled at init
32033203
if bufferSize > zds.staticSize - size_of::<ZSTD_DCtx>() {
32043204
return Error::dictionary_corrupted.to_error_code();
32053205
}
@@ -3242,7 +3242,7 @@ pub unsafe extern "C" fn ZSTD_decompressStream(
32423242
if ERR_isError(err_code_4) {
32433243
return err_code_4;
32443244
}
3245-
assert!(!ip.is_null());
3245+
debug_assert!(!ip.is_null());
32463246
ip = ip.add(neededInSize);
32473247
// Function modifies the stage so we must break
32483248
continue;
@@ -3358,7 +3358,7 @@ pub unsafe extern "C" fn ZSTD_decompressStream(
33583358
nextSrcSizeHint = nextSrcSizeHint.wrapping_add(
33593359
ZSTD_blockHeaderSize * (zds.stage.to_next_input_type() == NextInputType::Block) as size_t,
33603360
);
3361-
assert!(zds.inPos <= nextSrcSizeHint);
3361+
debug_assert!(zds.inPos <= nextSrcSizeHint);
33623362
// part already loaded
33633363
nextSrcSizeHint = nextSrcSizeHint.wrapping_sub(zds.inPos);
33643364
nextSrcSizeHint

lib/decompress/zstd_decompress_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ unsafe fn ZSTD_overlapCopy8(op: &mut *mut u8, ip: &mut *const u8, offset: size_t
10691069
*ip = (*ip).add(8);
10701070
*op = (*op).add(8);
10711071

1072-
assert!(unsafe { (*op).offset_from(*ip) } >= 8);
1072+
debug_assert!(unsafe { (*op).offset_from(*ip) } >= 8);
10731073
}
10741074

10751075
/// Specialized version of memcpy() that is allowed to READ up to WILDCOPY_OVERLENGTH past the input buffer

0 commit comments

Comments
 (0)