@@ -86,7 +86,7 @@ pub fn diff(base: &[u8], data: &[u8]) -> io::Result<Vec<u8>> {
8686 unsafe {
8787 let cctx = ZSTD_createCCtx ( ) ;
8888 if cctx. is_null ( ) {
89- return Err ( io:: Error :: new ( io :: ErrorKind :: Other , "cannot create CCtx" ) ) ;
89+ return Err ( io:: Error :: other ( "cannot create CCtx" ) ) ;
9090 }
9191
9292 let max_outsize = ZSTD_compressBound ( data. len ( ) ) ;
@@ -107,7 +107,7 @@ pub fn diff(base: &[u8], data: &[u8]) -> io::Result<Vec<u8>> {
107107
108108 if ZSTD_isError ( outsize) != 0 {
109109 let msg = format ! ( "cannot compress ({})" , explain_error( outsize) ) ;
110- Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) )
110+ Err ( io:: Error :: other ( msg) )
111111 } else {
112112 buf. set_len ( outsize) ;
113113 Ok ( buf)
@@ -120,18 +120,19 @@ pub fn apply(base: &[u8], delta: &[u8]) -> io::Result<Vec<u8>> {
120120 unsafe {
121121 let dctx = ZSTD_createDCtx ( ) ;
122122 if dctx. is_null ( ) {
123- return Err ( io:: Error :: new ( io :: ErrorKind :: Other , "cannot create DCtx" ) ) ;
123+ return Err ( io:: Error :: other ( "cannot create DCtx" ) ) ;
124124 }
125125 ZSTD_DCtx_setMaxWindowSize ( dctx, 1 << ZSTD_WINDOWLOG_MAX ) ;
126126
127127 let size = ZSTD_findDecompressedSize ( delta. as_ptr ( ) as * const c_void , delta. len ( ) ) as usize ;
128128 if size == ZSTD_CONTENTSIZE_ERROR as usize || size == ZSTD_CONTENTSIZE_UNKNOWN as usize {
129129 ZSTD_freeDCtx ( dctx) ;
130130 let msg = "cannot get decompress size" ;
131- return Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) ) ;
131+ return Err ( io:: Error :: other ( msg) ) ;
132132 }
133133
134134 let mut buf: Vec < u8 > = Vec :: with_capacity ( size) ;
135+ let _remaining = buf. spare_capacity_mut ( ) ;
135136 buf. set_len ( size) ;
136137
137138 let outsize = ZSTD_decompress_usingDict (
@@ -147,13 +148,13 @@ pub fn apply(base: &[u8], delta: &[u8]) -> io::Result<Vec<u8>> {
147148
148149 if ZSTD_isError ( outsize) != 0 {
149150 let msg = format ! ( "cannot decompress ({})" , explain_error( outsize) ) ;
150- Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) )
151+ Err ( io:: Error :: other ( msg) )
151152 } else if outsize != size {
152153 let msg = format ! (
153154 "decompress size mismatch (expected {}, got {})" ,
154155 size, outsize
155156 ) ;
156- Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) )
157+ Err ( io:: Error :: other ( msg) )
157158 } else {
158159 Ok ( buf)
159160 }
0 commit comments