summaryrefslogtreecommitdiff
path: root/tests/notes
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-03-04 01:23:20 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-17 20:50:02 +0100
commit385449b1df593440abcf6636c81eb5ea19b1d1a1 (patch)
tree71e4417be6058d6df44e4e105f4c60b56d889359 /tests/notes
parent9bbc8f350b80a5a6e94651ec667cf9e5d545b317 (diff)
downloadlibgit2-385449b1df593440abcf6636c81eb5ea19b1d1a1.tar.gz
note: use a git_buf to return the default namespacecmn/notes-buf
The caller has otherwise no way to know how long the string will be allocated or ability to free it. This fixes #2944.
Diffstat (limited to 'tests/notes')
-rw-r--r--tests/notes/notes.c7
-rw-r--r--tests/notes/notesref.c10
2 files changed, 12 insertions, 5 deletions
diff --git a/tests/notes/notes.c b/tests/notes/notes.c
index d3b915e15..a91bf5bdf 100644
--- a/tests/notes/notes.c
+++ b/tests/notes/notes.c
@@ -1,5 +1,7 @@
#include "clar_libgit2.h"
+#include "buffer.h"
+
static git_repository *_repo;
static git_signature *_sig;
@@ -150,7 +152,7 @@ void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_def
{
git_oid note_oid, target_oid;
git_note *note, *default_namespace_note;
- const char *default_ref;
+ git_buf default_ref = GIT_BUF_INIT;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(git_note_default_ref(&default_ref, _repo));
@@ -158,11 +160,12 @@ void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_def
create_note(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
cl_git_pass(git_note_read(&note, _repo, NULL, &target_oid));
- cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref, &target_oid));
+ cl_git_pass(git_note_read(&default_namespace_note, _repo, git_buf_cstr(&default_ref), &target_oid));
assert_note_equal(note, "hello world\n", &note_oid);
assert_note_equal(default_namespace_note, "hello world\n", &note_oid);
+ git_buf_free(&default_ref);
git_note_free(note);
git_note_free(default_namespace_note);
}
diff --git a/tests/notes/notesref.c b/tests/notes/notesref.c
index 11391e448..4159ddc0d 100644
--- a/tests/notes/notesref.c
+++ b/tests/notes/notesref.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "notes.h"
+#include "buffer.h"
static git_repository *_repo;
static git_note *_note;
@@ -33,7 +34,7 @@ void test_notes_notesref__cleanup(void)
void test_notes_notesref__config_corenotesref(void)
{
git_oid oid, note_oid;
- const char *default_ref;
+ git_buf default_ref = GIT_BUF_INIT;
cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com"));
cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
@@ -55,10 +56,13 @@ void test_notes_notesref__config_corenotesref(void)
cl_assert_equal_oid(git_note_id(_note), &note_oid);
cl_git_pass(git_note_default_ref(&default_ref, _repo));
- cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref);
+ cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref.ptr);
+ git_buf_clear(&default_ref);
cl_git_pass(git_config_delete_entry(_cfg, "core.notesRef"));
cl_git_pass(git_note_default_ref(&default_ref, _repo));
- cl_assert_equal_s(GIT_NOTES_DEFAULT_REF, default_ref);
+ cl_assert_equal_s(GIT_NOTES_DEFAULT_REF, default_ref.ptr);
+
+ git_buf_free(&default_ref);
}