Merge branch 'jk/read-in-full'
Code clean-up to prevent future mistakes by copying and pasting code that checks the result of read_in_full() function. * jk/read-in-full: worktree: check the result of read_in_full() worktree: use xsize_t to access file size distinguish error versus short read from read_in_full() avoid looking at errno for short read_in_full() returns prefer "!=" when checking read_in_full() result notes-merge: drop dead zero-write code files-backend: prefer "0" for write_in_full() error check
This commit is contained in:
11
sha1_file.c
11
sha1_file.c
@ -1748,10 +1748,15 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
|
||||
ret = index_mem(sha1, "", size, type, path, flags);
|
||||
} else if (size <= SMALL_FILE_SIZE) {
|
||||
char *buf = xmalloc(size);
|
||||
if (size == read_in_full(fd, buf, size))
|
||||
ret = index_mem(sha1, buf, size, type, path, flags);
|
||||
ssize_t read_result = read_in_full(fd, buf, size);
|
||||
if (read_result < 0)
|
||||
ret = error_errno("read error while indexing %s",
|
||||
path ? path : "<unknown>");
|
||||
else if (read_result != size)
|
||||
ret = error("short read while indexing %s",
|
||||
path ? path : "<unknown>");
|
||||
else
|
||||
ret = error_errno("short read");
|
||||
ret = index_mem(sha1, buf, size, type, path, flags);
|
||||
free(buf);
|
||||
} else {
|
||||
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
|
Reference in New Issue
Block a user