Commit a64bf21bbb5f79d3ac523087a2953a35adbb896f

nulltoken 2011-06-15T16:05:33

blob: Fix git_blob_create_fromfile()

diff --git a/src/blob.c b/src/blob.c
index c95d018..ceb2c9c 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -119,9 +119,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
 		ssize_t read_len;
 
 		if (!islnk)
-			read_len = gitfo_read(fd, buffer, sizeof(buffer));
+			read_len = gitfo_read(fd, buffer, (size_t)(size < sizeof(buffer) ? size : sizeof(buffer)));
 		else
-			read_len = gitfo_readlink(full_path, buffer, sizeof(buffer));
+			read_len = gitfo_readlink(full_path, buffer, (size_t)size);
 
 		if (read_len < 0) {
 			if (!islnk)
diff --git a/src/fileops.c b/src/fileops.c
index 2a78764..2136c91 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -97,7 +97,7 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
 		cnt -= r;
 		b += r;
 	}
-	return GIT_SUCCESS;
+	return (int)(b - (char *)buf);
 }
 
 int gitfo_write(git_file fd, void *buf, size_t cnt)