diff options
| author | Junio C Hamano <gitster@pobox.com> | 2017-10-03 15:42:49 +0900 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2017-10-03 15:42:49 +0900 |
| commit | cb1083ca23c2f78140b66b925ed0b82fe400eea5 (patch) | |
| tree | c78509d2b9fbe79c99ed1acb83bf43886b4d0c0c /pack-write.c | |
| parent | d4e93836a6a072e392b20d7daf604fd41e15ecf9 (diff) | |
| parent | 8a1a8d2ad1b41a0a28d37d1d21ee9620a23e91eb (diff) | |
| download | git-cb1083ca23c2f78140b66b925ed0b82fe400eea5.tar.xz | |
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
Diffstat (limited to 'pack-write.c')
| -rw-r--r-- | pack-write.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/pack-write.c b/pack-write.c index a333ec6754..fea6284192 100644 --- a/pack-write.c +++ b/pack-write.c @@ -213,14 +213,19 @@ void fixup_pack_header_footer(int pack_fd, git_SHA_CTX old_sha1_ctx, new_sha1_ctx; struct pack_header hdr; char *buf; + ssize_t read_result; git_SHA1_Init(&old_sha1_ctx); git_SHA1_Init(&new_sha1_ctx); if (lseek(pack_fd, 0, SEEK_SET) != 0) die_errno("Failed seeking to start of '%s'", pack_name); - if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr)) + read_result = read_in_full(pack_fd, &hdr, sizeof(hdr)); + if (read_result < 0) die_errno("Unable to reread header of '%s'", pack_name); + else if (read_result != sizeof(hdr)) + die_errno("Unexpected short read for header of '%s'", + pack_name); if (lseek(pack_fd, 0, SEEK_SET) != 0) die_errno("Failed seeking to start of '%s'", pack_name); git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr)); |
