@@ -404,7 +404,7 @@ fn convert_whence(whence: SeekStyle) -> i32 {
404
404
impl * libc:: FILE : Reader {
405
405
fn read ( bytes : & [ mut u8] , len : uint ) -> uint {
406
406
do vec:: as_mut_buf ( bytes) |buf_p, buf_len| {
407
- assert buf_len < = len;
407
+ assert buf_len > = len;
408
408
409
409
let count = libc:: fread ( buf_p as * mut c_void , 1 u as size_t ,
410
410
len as size_t , self ) ;
@@ -1208,6 +1208,29 @@ mod tests {
1208
1208
}
1209
1209
}
1210
1210
1211
+ #[ test]
1212
+ #[ should_fail]
1213
+ fn test_read_buffer_too_small ( ) {
1214
+ let path = & Path ( "tmp/lib-io-test-read-buffer-too-small.tmp" ) ;
1215
+ // ensure the file exists
1216
+ io:: file_writer ( path, [ io:: Create ] ) . get ( ) ;
1217
+
1218
+ let file = io:: file_reader ( path) . get ( ) ;
1219
+ let mut buf = vec:: from_elem ( 5 , 0 ) ;
1220
+ file. read ( buf, 6 ) ; // this should fail because buf is too small
1221
+ }
1222
+
1223
+ #[ test]
1224
+ fn test_read_buffer_big_enough ( ) {
1225
+ let path = & Path ( "tmp/lib-io-test-read-buffer-big-enough.tmp" ) ;
1226
+ // ensure the file exists
1227
+ io:: file_writer ( path, [ io:: Create ] ) . get ( ) ;
1228
+
1229
+ let file = io:: file_reader ( path) . get ( ) ;
1230
+ let mut buf = vec:: from_elem ( 5 , 0 ) ;
1231
+ file. read ( buf, 4 ) ; // this should succeed because buf is big enough
1232
+ }
1233
+
1211
1234
#[ test]
1212
1235
fn test_write_empty ( ) {
1213
1236
let file = io:: file_writer ( & Path ( "tmp/lib-io-test-write-empty.tmp" ) ,
0 commit comments