зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
06f46f237a
Коммит
564bde9ae6
5
entry.c
5
entry.c
|
@ -244,7 +244,8 @@ static int write_entry(struct cache_entry *ce,
|
||||||
char *new;
|
char *new;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
size_t wrote, newsize = 0;
|
ssize_t wrote;
|
||||||
|
size_t newsize = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const struct submodule *sub;
|
const struct submodule *sub;
|
||||||
|
|
||||||
|
@ -319,7 +320,7 @@ static int write_entry(struct cache_entry *ce,
|
||||||
fstat_done = fstat_output(fd, state, &st);
|
fstat_done = fstat_output(fd, state, &st);
|
||||||
close(fd);
|
close(fd);
|
||||||
free(new);
|
free(new);
|
||||||
if (wrote != size)
|
if (wrote < 0)
|
||||||
return error("unable to write file %s", path);
|
return error("unable to write file %s", path);
|
||||||
break;
|
break;
|
||||||
case S_IFGITLINK:
|
case S_IFGITLINK:
|
||||||
|
|
|
@ -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;
|
written = len <= maxlen ? write_in_full(fd, logrec, len) : -1;
|
||||||
free(logrec);
|
free(logrec);
|
||||||
if (written != len)
|
if (written < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -539,7 +539,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
|
||||||
kept = 0;
|
kept = 0;
|
||||||
wrote = write_in_full(fd, buf, readlen);
|
wrote = write_in_full(fd, buf, readlen);
|
||||||
|
|
||||||
if (wrote != readlen)
|
if (wrote < 0)
|
||||||
goto close_and_exit;
|
goto close_and_exit;
|
||||||
}
|
}
|
||||||
if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||
|
if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||
|
||||||
|
|
Загрузка…
Ссылка в новой задаче