summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2011-06-30 07:12:42 -0700
committerVicent Martí <tanoku@gmail.com>2011-06-30 07:12:42 -0700
commit1f61e301be9088bbe9e56411f669fce8a82ccb8d (patch)
tree86cead0c7b93d038f12c1a0e751768c289005097
parent02bc2d2f2788a17fda643462cd7e1f79f261e11d (diff)
parentfe5babacd6a2a8f358603404ee27327c20830c03 (diff)
downloadlibgit2-1f61e301be9088bbe9e56411f669fce8a82ccb8d.tar.gz
Merge pull request #287 from kiryl/development
filebuf: fix endless loop on writing buf > WRITE_BUFFER_SIZE
-rw-r--r--src/filebuf.c1
-rw-r--r--tests/t00-core.c14
2 files changed, 15 insertions, 0 deletions
diff --git a/src/filebuf.c b/src/filebuf.c
index ca13e6181..01b36bcff 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -331,6 +331,7 @@ int git_filebuf_write(git_filebuf *file, const void *buff, size_t len)
error = file->write(file, buf, len);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to write to buffer");
+ return GIT_SUCCESS;
}
}
}
diff --git a/tests/t00-core.c b/tests/t00-core.c
index aa0008576..31ed8c38b 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -692,6 +692,19 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
must_pass(gitfo_unlink(test));
END_TEST
+BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly")
+ git_filebuf file;
+ char test[] = "test";
+ unsigned char buf[4096 * 4]; /* 2 * WRITE_BUFFER_SIZE */
+
+ memset(buf, 0xfe, sizeof(buf));
+ must_pass(git_filebuf_open(&file, test, 0));
+ must_pass(git_filebuf_write(&file, buf, sizeof(buf)));
+ must_pass(git_filebuf_commit(&file));
+
+ must_pass(gitfo_unlink(test));
+END_TEST
+
BEGIN_SUITE(core)
ADD_TEST(string0);
ADD_TEST(string1);
@@ -716,4 +729,5 @@ BEGIN_SUITE(core)
ADD_TEST(filebuf0);
ADD_TEST(filebuf1);
+ ADD_TEST(filebuf2);
END_SUITE