Skip to content

Commit 564bde9

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06f46f2 commit 564bde9

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

entry.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ static int write_entry(struct cache_entry *ce,
244244
char *new;
245245
struct strbuf buf = STRBUF_INIT;
246246
unsigned long size;
247-
size_t wrote, newsize = 0;
247+
ssize_t wrote;
248+
size_t newsize = 0;
248249
struct stat st;
249250
const struct submodule *sub;
250251

@@ -319,7 +320,7 @@ static int write_entry(struct cache_entry *ce,
319320
fstat_done = fstat_output(fd, state, &st);
320321
close(fd);
321322
free(new);
322-
if (wrote != size)
323+
if (wrote < 0)
323324
return error("unable to write file %s", path);
324325
break;
325326
case S_IFGITLINK:

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
20392039

20402040
written = len <= maxlen ? write_in_full(fd, logrec, len) : -1;
20412041
free(logrec);
2042-
if (written != len)
2042+
if (written < 0)
20432043
return -1;
20442044

20452045
return 0;

streaming.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
539539
kept = 0;
540540
wrote = write_in_full(fd, buf, readlen);
541541

542-
if (wrote != readlen)
542+
if (wrote < 0)
543543
goto close_and_exit;
544544
}
545545
if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||

0 commit comments

Comments
 (0)