Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: fix uv_fs_write when using an empty buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Feb 26, 2014
1 parent 6d463bf commit 3a8767e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/unix/fs.c
Expand Up @@ -598,7 +598,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
# endif
written = 0;
index = 0;
r = 1;
r = 0;
do {
if (req->bufs[index].len > 0) {
r = pwrite(req->file,
Expand All @@ -609,7 +609,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
written += r;
}
index++;
} while (index < req->nbufs && r > 0);
} while (index < req->nbufs && r >= 0);
if (written > 0)
r = written;
}
Expand Down
32 changes: 32 additions & 0 deletions test/test-fs.c
Expand Up @@ -735,6 +735,38 @@ TEST_IMPL(fs_file_sync) {
}


TEST_IMPL(fs_file_write_null_buffer) {
int r;

/* Setup. */
unlink("test_file");

loop = uv_default_loop();

r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0);
ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);

iov = uv_buf_init(NULL, 0);
r = uv_fs_write(loop, &write_req, open_req1.result, &iov, 1, -1, NULL);
ASSERT(r == 0);
ASSERT(write_req.result == 0);
uv_fs_req_cleanup(&write_req);

r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);

unlink("test_file");

MAKE_VALGRIND_HAPPY();
return 0;
}


TEST_IMPL(fs_async_dir) {
int r;

Expand Down
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -183,6 +183,7 @@ TEST_DECLARE (fs_file_nametoolong)
TEST_DECLARE (fs_file_loop)
TEST_DECLARE (fs_file_async)
TEST_DECLARE (fs_file_sync)
TEST_DECLARE (fs_file_write_null_buffer)
TEST_DECLARE (fs_async_dir)
TEST_DECLARE (fs_async_sendfile)
TEST_DECLARE (fs_fstat)
Expand Down Expand Up @@ -506,6 +507,7 @@ TASK_LIST_START
TEST_ENTRY (fs_file_loop)
TEST_ENTRY (fs_file_async)
TEST_ENTRY (fs_file_sync)
TEST_ENTRY (fs_file_write_null_buffer)
TEST_ENTRY (fs_async_dir)
TEST_ENTRY (fs_async_sendfile)
TEST_ENTRY (fs_fstat)
Expand Down

0 comments on commit 3a8767e

Please sign in to comment.