summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-09-13 13:16:28 -0400
committerJunio C Hamano <gitster@pobox.com>2017-09-14 15:17:59 +0900
commit564bde9ae69dc3d60e764078745275b637f90991 (patch)
tree45365f924c0622698493ee62ee0ede6c51133e4c
parent06f46f237afa823c0a2775e60ed8fbd80e7c751f (diff)
downloadgit-564bde9ae69dc3d60e764078745275b637f90991.tar.gz
convert less-trivial versions of "write_in_full() != len"
The prior commit converted many sites to check the return value of write_in_full() for negativity, rather than a mismatch with the input length. This patch covers similar cases, but where the return value is stored in an intermediate variable. These should get the same treatment, but they need to be reviewed more carefully since it would be a bug if the return value is stored in an unsigned type (which indeed, it is in one of the cases). Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--entry.c5
-rw-r--r--refs/files-backend.c2
-rw-r--r--streaming.c2
3 files changed, 5 insertions, 4 deletions
diff --git a/entry.c b/entry.c
index 65458f07a4..3c1818f1d4 100644
--- a/entry.c
+++ b/entry.c
@@ -244,7 +244,8 @@ static int write_entry(struct cache_entry *ce,
char *new;
struct strbuf buf = STRBUF_INIT;
unsigned long size;
- size_t wrote, newsize = 0;
+ ssize_t wrote;
+ size_t newsize = 0;
struct stat st;
const struct submodule *sub;
@@ -319,7 +320,7 @@ static int write_entry(struct cache_entry *ce,
fstat_done = fstat_output(fd, state, &st);
close(fd);
free(new);
- if (wrote != size)
+ if (wrote < 0)
return error("unable to write file %s", path);
break;
case S_IFGITLINK:
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 924e8537f3..f21a954ce7 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2039,7 +2039,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
written = len <= maxlen ? write_in_full(fd, logrec, len) : -1;
free(logrec);
- if (written != len)
+ if (written < 0)
return -1;
return 0;
diff --git a/streaming.c b/streaming.c
index 9afa66b8be..c8b85e4498 100644
--- a/streaming.c
+++ b/streaming.c
@@ -539,7 +539,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
kept = 0;
wrote = write_in_full(fd, buf, readlen);
- if (wrote != readlen)
+ if (wrote < 0)
goto close_and_exit;
}
if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||