]> git.proxmox.com Git - libgit2.git/commitdiff
filebuf: fix endless loop on writing buf > WRITE_BUFFER_SIZE
authorKirill A. Shutemov <kirill@shutemov.name>
Wed, 29 Jun 2011 21:16:23 +0000 (00:16 +0300)
committerKirill A. Shutemov <kirill@shutemov.name>
Thu, 30 Jun 2011 13:19:19 +0000 (16:19 +0300)
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
src/filebuf.c
tests/t00-core.c

index ca13e6181d8ce8f0c10a1091bf820deb9fcae6b7..01b36bcffba20117c4ff28b295596eb8c43de163 100644 (file)
@@ -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;
                }
        }
 }
index aa0008576665e7990798d020433456ef5afeb188..31ed8c38bbba3e001467b22dd8de51ffacbeca53 100644 (file)
@@ -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