@@ -1729,7 +1729,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
17291729 seq : & [ u8 ] ,
17301730 mut nbSeq : core:: ffi:: c_int ,
17311731 offset : Offset ,
1732- ) -> size_t {
1732+ ) -> Result < size_t , Error > {
17331733 let maxDstSize = dst. capacity ( ) ;
17341734 let mut op = dst;
17351735 let mut litPtr = dctx. litPtr ;
@@ -1738,10 +1738,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
17381738 let vBase = dctx. virtualStart as * const u8 ;
17391739 let dictEnd = dctx. dictEnd as * const u8 ;
17401740 if nbSeq != 0 {
1741- let DStream = match BIT_DStream_t :: new ( seq) {
1742- Ok ( v) => v,
1743- Err ( _) => return Error :: corruption_detected. to_error_code ( ) ,
1744- } ;
1741+ let DStream = BIT_DStream_t :: new ( seq) . map_err ( |_| Error :: corruption_detected) ?;
17451742 dctx. fseEntropy = true ;
17461743 let mut seqState = dctx. new_seq_state ( DStream ) ;
17471744
@@ -1759,7 +1756,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
17591756 break ;
17601757 }
17611758
1762- let oneSeqSize = match ZSTD_execSequenceSplitLitBuffer (
1759+ let oneSeqSize = ZSTD_execSequenceSplitLitBuffer (
17631760 op. subslice ( ..) ,
17641761 op. as_mut_ptr_range ( ) . end ,
17651762 litPtr. add ( sequence. litLength ) . sub ( WILDCOPY_OVERLENGTH ) ,
@@ -1769,10 +1766,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
17691766 prefixStart,
17701767 vBase,
17711768 dictEnd,
1772- ) {
1773- Ok ( sequenceLength) => sequenceLength,
1774- Err ( err) => return err. to_error_code ( ) ,
1775- } ;
1769+ ) ?;
17761770
17771771 op = op. subslice ( oneSeqSize..) ;
17781772 nbSeq -= 1 ;
@@ -1782,7 +1776,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
17821776 let leftoverLit = dctx. litBufferEnd . offset_from_unsigned ( litPtr) ;
17831777 if leftoverLit != 0 {
17841778 if leftoverLit > op. capacity ( ) {
1785- return Error :: dstSize_tooSmall. to_error_code ( ) ;
1779+ return Err ( Error :: dstSize_tooSmall) ;
17861780 }
17871781 ZSTD_safecopyDstBeforeSrc ( op. as_mut_ptr ( ) , litPtr, leftoverLit) ;
17881782 sequence. litLength = sequence. litLength . wrapping_sub ( leftoverLit) ;
@@ -1791,7 +1785,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
17911785 litPtr = dctx. litExtraBuffer . as_mut_ptr ( ) ;
17921786 litBufferEnd = dctx. litExtraBuffer [ ZSTD_LITBUFFEREXTRASIZE ..] . as_mut_ptr ( ) ;
17931787 dctx. litBufferLocation = LitLocation :: ZSTD_not_in_dst ;
1794- let oneSeqSize_0 = match ZSTD_execSequence (
1788+ let oneSeqSize_0 = ZSTD_execSequence (
17951789 op. subslice ( ..) ,
17961790 op. as_mut_ptr_range ( ) . end ,
17971791 sequence,
@@ -1800,10 +1794,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
18001794 prefixStart,
18011795 vBase,
18021796 dictEnd,
1803- ) {
1804- Ok ( size) => size,
1805- Err ( err) => return err. to_error_code ( ) ,
1806- } ;
1797+ ) ?;
18071798 op = op. subslice ( oneSeqSize_0..) ;
18081799 nbSeq -= 1 ;
18091800 }
@@ -1824,7 +1815,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
18241815
18251816 while nbSeq != 0 {
18261817 let sequence_0 = ZSTD_decodeSequence ( & mut seqState, offset, nbSeq == 1 ) ;
1827- let oneSeqSize_1 = match ZSTD_execSequence (
1818+ let oneSeqSize_1 = ZSTD_execSequence (
18281819 op. subslice ( ..) ,
18291820 op. as_mut_ptr_range ( ) . end ,
18301821 sequence_0,
@@ -1833,19 +1824,16 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
18331824 prefixStart,
18341825 vBase,
18351826 dictEnd,
1836- ) {
1837- Ok ( size) => size,
1838- Err ( err) => return err. to_error_code ( ) ,
1839- } ;
1827+ ) ?;
18401828 op = op. subslice ( oneSeqSize_1..) ;
18411829 nbSeq -= 1 ;
18421830 }
18431831 }
18441832 if nbSeq != 0 {
1845- return Error :: corruption_detected. to_error_code ( ) ;
1833+ return Err ( Error :: corruption_detected) ;
18461834 }
18471835 if !seqState. DStream . is_empty ( ) {
1848- return Error :: corruption_detected. to_error_code ( ) ;
1836+ return Err ( Error :: corruption_detected) ;
18491837 }
18501838
18511839 dctx. entropy . rep = seqState. prevOffset . map ( |v| v as u32 ) ;
@@ -1854,7 +1842,7 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
18541842 if dctx. litBufferLocation == LitLocation :: ZSTD_split {
18551843 let lastLLSize = litBufferEnd. offset_from_unsigned ( litPtr) ;
18561844 if lastLLSize > op. capacity ( ) {
1857- return Error :: dstSize_tooSmall. to_error_code ( ) ;
1845+ return Err ( Error :: dstSize_tooSmall) ;
18581846 }
18591847 if !op. is_null ( ) {
18601848 unsafe { core:: ptr:: copy ( litPtr, op. as_mut_ptr ( ) , lastLLSize) } ;
@@ -1867,15 +1855,15 @@ unsafe fn ZSTD_decompressSequences_bodySplitLitBuffer(
18671855
18681856 let lastLLSize_0 = litBufferEnd. offset_from_unsigned ( litPtr) ;
18691857 if lastLLSize_0 > op. capacity ( ) {
1870- return Error :: dstSize_tooSmall. to_error_code ( ) ;
1858+ return Err ( Error :: dstSize_tooSmall) ;
18711859 }
18721860
18731861 if !op. is_null ( ) {
18741862 unsafe { core:: ptr:: copy_nonoverlapping ( litPtr, op. as_mut_ptr ( ) , lastLLSize_0) } ;
18751863 op = op. subslice ( lastLLSize_0..) ;
18761864 }
18771865
1878- maxDstSize - op. capacity ( )
1866+ Ok ( maxDstSize - op. capacity ( ) )
18791867}
18801868
18811869#[ inline( always) ]
@@ -1965,7 +1953,7 @@ unsafe fn ZSTD_decompressSequencesSplitLitBuffer_default(
19651953 seqStart : & [ u8 ] ,
19661954 nbSeq : core:: ffi:: c_int ,
19671955 offset : Offset ,
1968- ) -> size_t {
1956+ ) -> Result < size_t , Error > {
19691957 ZSTD_decompressSequences_bodySplitLitBuffer ( dctx, dst, seqStart, nbSeq, offset)
19701958}
19711959
@@ -2231,7 +2219,7 @@ unsafe fn ZSTD_decompressSequencesSplitLitBuffer_bmi2(
22312219 seqStart : & [ u8 ] ,
22322220 nbSeq : core:: ffi:: c_int ,
22332221 offset : Offset ,
2234- ) -> size_t {
2222+ ) -> Result < size_t , Error > {
22352223 ZSTD_decompressSequences_bodySplitLitBuffer ( dctx, dst, seqStart, nbSeq, offset)
22362224}
22372225
@@ -2266,7 +2254,7 @@ unsafe fn ZSTD_decompressSequencesSplitLitBuffer(
22662254 seqStart : & [ u8 ] ,
22672255 nbSeq : core:: ffi:: c_int ,
22682256 offset : Offset ,
2269- ) -> size_t {
2257+ ) -> Result < size_t , Error > {
22702258 if dctx. bmi2 {
22712259 ZSTD_decompressSequencesSplitLitBuffer_bmi2 ( dctx, dst, seqStart, nbSeq, offset)
22722260 } else {
@@ -2434,7 +2422,10 @@ unsafe fn ZSTD_decompressBlock_internal_help(
24342422 }
24352423
24362424 if dctx. litBufferLocation == LitLocation :: ZSTD_split {
2437- ZSTD_decompressSequencesSplitLitBuffer ( dctx, dst, ip, nbSeq, offset)
2425+ match ZSTD_decompressSequencesSplitLitBuffer ( dctx, dst, ip, nbSeq, offset) {
2426+ Ok ( size) => size,
2427+ Err ( err) => err. to_error_code ( ) ,
2428+ }
24382429 } else {
24392430 match ZSTD_decompressSequences ( dctx, dst, ip, nbSeq, offset) {
24402431 Ok ( size) => size,
0 commit comments