Remove need to grow/zero buffer and add comment

This commit is contained in:
Michael Boulton 2020-08-18 16:19:50 +01:00
parent 051b9cd7b0
commit 0fc857204a
No known key found for this signature in database
GPG Key ID: 8A62CA0BE2E0197E
2 changed files with 3 additions and 13 deletions

View File

@ -3,7 +3,6 @@ package git
/*
#include <git2.h>
extern void _go_git_buf_fill_null(git_buf *buf);
extern void _go_git_populate_commit_sign_cb(git_rebase_options *opts);
*/
import "C"
@ -98,13 +97,9 @@ func commitSignCallback(_signature *C.git_buf, _signature_field *C.git_buf, _com
cstr := unsafe.Pointer(C.CString(bufData))
defer C.free(cstr)
// over-assign by a byte (see below)
if int(C.git_buf_grow(buf, clen+1)) != 0 {
return errors.New("could not grow buffer")
}
C._go_git_buf_fill_null(buf)
// libgit2 requires the contents of the buffer to be NULL-terminated.
// C.CString() guarantees that the returned buffer will be
// NULL-terminated, so we can safely copy the terminator.
if int(C.git_buf_set(buf, cstr, clen+1)) != 0 {
return errors.New("could not set buffer")
}

View File

@ -12,11 +12,6 @@ void _go_git_populate_apply_cb(git_apply_options *options)
options->hunk_cb = (git_apply_hunk_cb)hunkApplyCallback;
}
void _go_git_buf_fill_null(git_buf *buf)
{
memset(buf->ptr, '\0', buf->asize*sizeof(char));
}
void _go_git_populate_commit_sign_cb(git_rebase_options *opts)
{
opts->signing_cb = (git_commit_signing_cb)commitSignCallback;