Skip to content

Commit dcabef2

Browse files
committed
futils: produce improved error messages
1 parent e7be6b7 commit dcabef2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util/futils.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,18 @@ int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len)
167167
/* p_read loops internally to read len bytes */
168168
read_size = p_read(fd, buf->ptr, len);
169169

170-
if (read_size != (ssize_t)len) {
170+
if (read_size < 0) {
171171
git_error_set(GIT_ERROR_OS, "failed to read descriptor");
172172
git_str_dispose(buf);
173173
return -1;
174174
}
175175

176+
if ((size_t)read_size != len) {
177+
git_error_set(GIT_ERROR_FILESYSTEM, "could not read (expected %" PRIuZ " bytes, read %" PRIuZ ")", len, (size_t)read_size);
178+
git_str_dispose(buf);
179+
return -1;
180+
}
181+
176182
buf->ptr[read_size] = '\0';
177183
buf->size = read_size;
178184

0 commit comments

Comments
 (0)