buffer: make use of EINVALID for growing a borrowed buffer

This explains more closely what happens. While here, set an error
message.
This commit is contained in:
Carlos Martín Nieto 2015-06-24 19:32:56 +02:00
parent 189aad45af
commit a65992355d
2 changed files with 5 additions and 3 deletions

View File

@ -41,8 +41,10 @@ int git_buf_try_grow(
if (buf->ptr == git_buf__oom)
return -1;
if (buf->asize == 0 && buf->size != 0)
return GIT_EINVALIDSPEC;
if (buf->asize == 0 && buf->size != 0) {
giterr_set(GITERR_INVALID, "cannot grow a borrowed buffer");
return GIT_EINVALID;
}
if (!target_size)
target_size = buf->size;

View File

@ -1164,5 +1164,5 @@ void test_core_buffer__dont_grow_borrowed(void)
cl_assert_equal_i(0, buf.asize);
cl_assert_equal_i(strlen(somestring) + 1, buf.size);
cl_git_fail_with(GIT_EINVALIDSPEC, git_buf_grow(&buf, 1024));
cl_git_fail_with(GIT_EINVALID, git_buf_grow(&buf, 1024));
}