Skip to content

Commit a42d2d4

Browse files
committed
Fix a bug where .write([]) would always fail.
1 parent 444a16a commit a42d2d4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/libcore/io.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,8 @@ impl<T: Writer, C> {base: T, cleanup: C}: Writer {
377377
impl *libc::FILE: Writer {
378378
fn write(v: &[const u8]) {
379379
do vec::as_const_buf(v) |vbuf, len| {
380-
let nout = libc::fwrite(vbuf as *c_void, len as size_t,
381-
1u as size_t, self);
382-
if nout < 1 as size_t {
380+
let nout = libc::fwrite(vbuf as *c_void, 1, len as size_t, self);
381+
if nout != len as size_t {
383382
error!("error writing buffer");
384383
log(error, os::last_os_error());
385384
fail;
@@ -959,6 +958,13 @@ mod tests {
959958
}
960959
}
961960

961+
#[test]
962+
fn test_write_empty() {
963+
let file = io::file_writer(&Path("tmp/lib-io-test-write-empty.tmp"),
964+
[io::Create]).get();
965+
file.write([]);
966+
}
967+
962968
#[test]
963969
fn file_writer_bad_name() {
964970
match io::file_writer(&Path("?/?"), ~[]) {

0 commit comments

Comments
 (0)