From 971e18b585e2b3e1c34c0394efdefb3794a65a74 Mon Sep 17 00:00:00 2001 From: Michael Boulton Date: Tue, 18 Aug 2020 15:16:33 +0100 Subject: [PATCH] Revert "simplify setting buffers" This reverts commit d2137760e0887bd996f437313aba0ba166f7bc52. Causes libgit2 to abort --- rebase.go | 9 ++++++++- wrapper.c | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rebase.go b/rebase.go index aa34c9e..2144329 100644 --- a/rebase.go +++ b/rebase.go @@ -98,7 +98,14 @@ func commitSignCallback(_signature *C.git_buf, _signature_field *C.git_buf, _com cstr := unsafe.Pointer(C.CString(bufData)) defer C.free(cstr) - if int(C.git_buf_set(buf, cstr, clen)) != 0 { + // 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) + + if int(C.git_buf_set(buf, cstr, clen+1)) != 0 { return errors.New("could not set buffer") } diff --git a/wrapper.c b/wrapper.c index 90b0e1e..6bdc11a 100644 --- a/wrapper.c +++ b/wrapper.c @@ -12,6 +12,11 @@ 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;