From 3d1c9f612d78c6c235a3f38af226300fb6dd7dd6 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 9 May 2013 06:45:06 -0700 Subject: Fix git_repository_message docs This clarifies the docs for git_repository_message and also adds to the tests to explicitly check NUL termination of data when the output buffer is smaller than the message size. There is a minor behavior change so that a non-NULL output buffer will always be NUL terminated (at length zero) if an error occurs. --- tests-clar/repo/message.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests-clar') diff --git a/tests-clar/repo/message.c b/tests-clar/repo/message.c index 59487d51b..629d40c12 100644 --- a/tests-clar/repo/message.c +++ b/tests-clar/repo/message.c @@ -35,13 +35,18 @@ void test_repo_message__message(void) len = git_repository_message(NULL, 0, _repo); cl_assert(len > 0); + _actual = git__malloc(len + 1); cl_assert(_actual != NULL); + /* Test non truncation */ cl_assert(git_repository_message(_actual, len, _repo) > 0); - _actual[len] = '\0'; cl_assert_equal_s(expected, _actual); + /* Test truncation and that trailing NUL is inserted */ + cl_assert(git_repository_message(_actual, 6, _repo) > 0); + cl_assert_equal_s("Test\n", _actual); + cl_git_pass(p_unlink(git_buf_cstr(&_path))); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo)); } -- cgit v1.2.3