@@ -101,7 +101,7 @@ public void CheckNullRead ()
101
101
Assert . Ignore ( "Requires iOS 9.0+ or macOS 10.11+" ) ;
102
102
MemoryStream backing = new MemoryStream ( compressed_data ) ;
103
103
DeflateStream decompressing = new DeflateStream ( backing , CompressionMode . Decompress , CompressionAlgorithm . Zlib ) ;
104
- Assert . Throws < ArgumentNullException > ( ( ) => decompressing . Read ( null , 0 , 20 ) ) ;
104
+ Assert . Throws < ArgumentNullException > ( ( ) => IgnoreReturnValue ( decompressing . Read ( null , 0 , 20 ) ) ) ;
105
105
}
106
106
107
107
[ Test ]
@@ -112,7 +112,7 @@ public void CheckCompressingRead ()
112
112
byte [ ] dummy = new byte [ 20 ] ;
113
113
MemoryStream backing = new MemoryStream ( ) ;
114
114
DeflateStream compressing = new DeflateStream ( backing , CompressionMode . Compress , CompressionAlgorithm . Zlib ) ;
115
- Assert . Throws < InvalidOperationException > ( ( ) => compressing . Read ( dummy , 0 , 20 ) ) ;
115
+ Assert . Throws < InvalidOperationException > ( ( ) => IgnoreReturnValue ( compressing . Read ( dummy , 0 , 20 ) ) ) ;
116
116
}
117
117
118
118
[ Test ]
@@ -123,7 +123,7 @@ public void CheckRangeRead ()
123
123
byte [ ] dummy = new byte [ 20 ] ;
124
124
MemoryStream backing = new MemoryStream ( compressed_data ) ;
125
125
DeflateStream decompressing = new DeflateStream ( backing , CompressionMode . Decompress , CompressionAlgorithm . Zlib ) ;
126
- Assert . Throws < ArgumentException > ( ( ) => decompressing . Read ( dummy , 10 , 20 ) ) ;
126
+ Assert . Throws < ArgumentException > ( ( ) => IgnoreReturnValue ( decompressing . Read ( dummy , 10 , 20 ) ) ) ;
127
127
}
128
128
129
129
[ Test ]
@@ -135,7 +135,7 @@ public void CheckClosedRead ()
135
135
MemoryStream backing = new MemoryStream ( compressed_data ) ;
136
136
DeflateStream decompressing = new DeflateStream ( backing , CompressionMode . Decompress , CompressionAlgorithm . Zlib ) ;
137
137
decompressing . Close ( ) ;
138
- Assert . Throws < ObjectDisposedException > ( ( ) => decompressing . Read ( dummy , 0 , 20 ) ) ;
138
+ Assert . Throws < ObjectDisposedException > ( ( ) => IgnoreReturnValue ( decompressing . Read ( dummy , 0 , 20 ) ) ) ;
139
139
}
140
140
141
141
[ Test ]
@@ -335,7 +335,13 @@ public void Bug19313 ()
335
335
byte [ ] buffer = new byte [ 512 ] ;
336
336
using ( var backing = new Bug19313Stream ( compressed_data ) )
337
337
using ( var decompressing = new DeflateStream ( backing , CompressionMode . Decompress , CompressionAlgorithm . Zlib ) )
338
- decompressing . Read ( buffer , 0 , buffer . Length ) ;
338
+ IgnoreReturnValue ( decompressing . Read ( buffer , 0 , buffer . Length ) ) ;
339
+ }
340
+
341
+ // Call this with the return value from CompressionStream.Read to avoid:
342
+ // error CA2022: Avoid inexact read with 'Compression.CompressionStream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
343
+ void IgnoreReturnValue ( int value )
344
+ {
339
345
}
340
346
}
341
347
}
0 commit comments