diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2006-07-10 01:32:33 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2006-07-10 01:32:33 +0000 |
commit | a039d9359aa51d9d07bfe33fae14f4beae76f5b5 (patch) | |
tree | 1735f6be70eac1029a36fb2593bcb3fdb1ab2cc7 /usr.bin | |
parent | 5c60d32f68daf0858f957d2c226ccb70809c76dd (diff) |
handle 0 sized files correctly, tested by brad@ thanks
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/remote.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/usr.bin/cvs/remote.c b/usr.bin/cvs/remote.c index 4b1943fcc83..67eb6323ad9 100644 --- a/usr.bin/cvs/remote.c +++ b/usr.bin/cvs/remote.c @@ -1,4 +1,4 @@ -/* $OpenBSD: remote.c,v 1.3 2006/07/09 01:47:20 joris Exp $ */ +/* $OpenBSD: remote.c,v 1.4 2006/07/10 01:32:32 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -113,14 +113,18 @@ cvs_remote_receive_file(size_t len) else in = current_cvsroot->cr_srvout; - data = xmalloc(len); - ret = fread(data, sizeof(char), len, in); - if (ret != len) - fatal("length mismatch, expected %ld, got %ld", len, ret); - bp = cvs_buf_alloc(len, BUF_AUTOEXT); - cvs_buf_set(bp, data, len, 0); - xfree(data); + + if (len != 0) { + data = xmalloc(len); + ret = fread(data, sizeof(char), len, in); + if (ret != len) + fatal("length mismatch, expected %ld, got %ld", + len, ret); + cvs_buf_set(bp, data, len, 0); + xfree(data); + } + return (bp); } @@ -155,12 +159,15 @@ cvs_remote_send_file(const char *path) bp = cvs_buf_load_fd(fd, BUF_AUTOEXT); fcont = cvs_buf_release(bp); - ret = fwrite(fcont, sizeof(char), st.st_size, out); - if (ret != st.st_size) - fatal("length mismatch, tried to write %lld only wrote %ld", - st.st_size, ret); - xfree(fcont); + if (fcont != NULL) { + ret = fwrite(fcont, sizeof(char), st.st_size, out); + if (ret != st.st_size) + fatal("tried to write %lld only wrote %ld", + st.st_size, ret); + xfree(fcont); + } + (void)close(fd); } |