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>

Jeff King committed Sep 13, 2017 at 13:16 UTC 564bde9ae69dc3d60e764078745275b637f90991
3 files changed +5 -4
entry.c
+3 -2
@@ -244,7 +244,8 @@ static int write_entry(struct cache_entry *ce,
244 char *new;
245 struct strbuf buf = STRBUF_INIT;
246 unsigned long size;
247 - size_t wrote, newsize = 0;
247 + ssize_t wrote;
248 + size_t newsize = 0;
249 struct stat st;
250 const struct submodule *sub;
251
@@ -319,7 +320,7 @@ static int write_entry(struct cache_entry *ce,
320 fstat_done = fstat_output(fd, state, &st);
321 close(fd);
322 free(new);
322 - if (wrote != size)
323 + if (wrote < 0)
324 return error("unable to write file %s", path);
325 break;
326 case S_IFGITLINK:
refs/files-backend.c
+1 -1
@@ -2039,7 +2039,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
2039
2040 written = len <= maxlen ? write_in_full(fd, logrec, len) : -1;
2041 free(logrec);
2042 - if (written != len)
2042 + if (written < 0)
2043 return -1;
2044
2045 return 0;
streaming.c
+1 -1
@@ -539,7 +539,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
539 kept = 0;
540 wrote = write_in_full(fd, buf, readlen);
541
542 - if (wrote != readlen)
542 + if (wrote < 0)
543 goto close_and_exit;
544 }
545 if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||