Commit a65992355dac71490f4b22b3f2c0d55a1beca01b

Carlos Martín Nieto 2015-06-24T19:32:56

buffer: make use of EINVALID for growing a borrowed buffer This explains more closely what happens. While here, set an error message.

diff --git a/src/buffer.c b/src/buffer.c
index c066d8e..1a5809c 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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;
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
index cc2d7bb..0e7026a 100644
--- a/tests/core/buffer.c
+++ b/tests/core/buffer.c
@@ -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));
 }